• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Storage类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.codename1.io.Storage的典型用法代码示例。如果您正苦于以下问题:Java Storage类的具体用法?Java Storage怎么用?Java Storage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Storage类属于com.codename1.io包,在下文中一共展示了Storage类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getLogContent

import com.codename1.io.Storage; //导入依赖的package包/类
/**
 * Retrieves the entire log content as a single long string to be used by
 * the application in any way it deems fit.
 * <p>
 * Note that if any buffered log is present (cf. {@link #logBuffered(java.lang.String)}),
 * it will be appended to the end of the string returned by this method.
 * 
 * @return The log data if successfully retrieved or null.
 * @throws com.parse4cn1.ParseException if anything goes wrong.
 */
public String getLogContent() throws ParseException {
    String text = null;
    try {
        Reader r = new InputStreamReader(Storage.getInstance().createInputStream(LOG_FILENAME));
        char[] buffer = new char[1024];
        int size = r.read(buffer);
        while (size > -1) {
            text += new String(buffer, 0, size);
            size = r.read(buffer);
        }
        r.close();
    } catch (Exception ex) {
        throw new ParseException("Retrieving log file contents failed:" 
                + ex.getMessage(), ex);
    }
    
    if (bufferedLog != null) {
        text += "\n\n================="
                + "\nBuffered logging:"
                + "\n=================\n"
                + bufferedLog;
    }
    
    return text;
}
 
开发者ID:sidiabale,项目名称:parse4cn1,代码行数:36,代码来源:Logger.java


示例2: testSimpleParseObjectSerialization

import com.codename1.io.Storage; //导入依赖的package包/类
private void testSimpleParseObjectSerialization() throws ParseException {
    System.out.println("============== testSimpleParseObjectSerialization()");
    assertEqual(ExternalizableParseObject.getClassName(), "ExternalizableParseObject");
    
    final ParseObject gameScore = ParseObject.create(classGameScore);
    gameScore.put("score", 1337);
    gameScore.put("rating", 4.5);
    gameScore.put("playerName", "Sean Plott");
    gameScore.put("cheatMode", false);
    gameScore.save();

    final ParseObject retrieved = serializeAndRetrieveParseObject(gameScore);
    compareParseObjects(gameScore, retrieved, null);

    // Make object dirty object
    gameScore.put("score", 1378);

    System.out.println("-------------- Serialization of dirty ParseObject should fail");
    assertFalse(Storage.getInstance().writeObject(gameScore.getObjectId(), gameScore.asExternalizable()),
            "Serialization of dirty ParseObject should be disallowed");

    gameScore.delete();
}
 
开发者ID:sidiabale,项目名称:parse4cn1,代码行数:24,代码来源:ParseObjectTest.java


示例3: MediaPlayer

import com.codename1.io.Storage; //导入依赖的package包/类
public MediaPlayer() {
    queue = (Queue)Storage.getInstance().readObject("queue");

    if (queue == null) {
        queue = new Queue();
    }

    // communicates using a thread-agnostic dispatcher
    this.statusChangeEvent = new EventDispatcher();
    this.statusChangeEvent.setBlocking(false);

    this.playingEvent = new EventDispatcher();
    this.playingEvent.setBlocking(false);

    this.coverLoadedEvent = new EventDispatcher();
    this.coverLoadedEvent.setBlocking(false);

    timer = new Timer();
}
 
开发者ID:martijn00,项目名称:MusicPlayerCodenameOne,代码行数:20,代码来源:MediaPlayer.java


示例4: getLanguage

import com.codename1.io.Storage; //导入依赖的package包/类
public String getLanguage()
{
    if (language != null)
        return language;

    language = (String) Storage.getInstance().readObject("API Base - language");
    if (language != null)
        return language;
    
    ArrayList<String> supportedLanguages = getSupportedLanguagesStorage();
    if (supportedLanguages != null && supportedLanguages.contains(Display.getInstance().getLocalizationManager().getLanguage()))
        language = Display.getInstance().getLocalizationManager().getLanguage();
    
    if (language != null)
        return language;
    else
        return "en";
}
 
开发者ID:martijn00,项目名称:MusicPlayerCodenameOne,代码行数:19,代码来源:Api.java


示例5: setFavorite

import com.codename1.io.Storage; //导入依赖的package包/类
/**
 * Toggles the favorite state and saves it to storage
 * @param currentListing the listing to toggle the state of
 * @param fav the new favorite state
 */
void setFavorite(Map<String, Object> currentListing, boolean fav) {
    if(fav) {
        favoritesList.add(currentListing);
        Storage.getInstance().writeObject("favoritesList", favoritesList);
    } else {
        String guid = (String)currentListing.get("guid");
        for(Map<String, Object> c : favoritesList) {
            if(c.get("guid").equals(guid)) {
                favoritesList.remove(c);
                Storage.getInstance().writeObject("favoritesList", favoritesList);
                return;
            }
        }
    }
}
 
开发者ID:codenameone,项目名称:codenameone-demos,代码行数:21,代码来源:PropertyCross.java


示例6: showPendingMessages

import com.codename1.io.Storage; //导入依赖的package包/类
private void showPendingMessages(Form f) {
    if(Storage.getInstance().exists("pendingMessages")) {
        java.util.List<Message> pendingMessages = (java.util.List<Message>)Storage.getInstance().readObject("pendingMessages");
        Message m = pendingMessages.get(0);
        pendingMessages.remove(0);
        respond(m);
        if(pendingMessages.size() == 0) {
            Storage.getInstance().deleteStorageFile("pendingMessages");
        } else {
            Storage.getInstance().writeObject("pendingMessages", pendingMessages);
            UITimer uit = new UITimer(() -> {
                showPendingMessages(f);
            });
            uit.schedule(3500, false, f);
        }
    }
}
 
开发者ID:codenameone,项目名称:codenameone-demos,代码行数:18,代码来源:SocialChat.java


示例7: addMessage

import com.codename1.io.Storage; //导入依赖的package包/类
/**
 * Stores the given message into the permanent storage
 */
private void addMessage(Message m) {
    String personId;
    
    // if this is a message to me then store based on sender otherwise store based on recepient
    if(m.getRecepientId().equals(tokenPrefix + uniqueId)) {
        personId = m.getSenderId();
    } else {
        personId = m.getRecepientId();
    }
    java.util.List messages = (java.util.List)Storage.getInstance().readObject(personId);
    if(messages == null) {
        messages = new ArrayList();
    }
    messages.add(m);
    Storage.getInstance().writeObject(personId, messages);
}
 
开发者ID:codenameone,项目名称:codenameone-demos,代码行数:20,代码来源:SocialChat.java


示例8: push

import com.codename1.io.Storage; //导入依赖的package包/类
@Override
public void push(String value) {
    // its a JSON message, otherwise its a notice to the user
    if(value.startsWith("{") || value.startsWith("[")) {
        try {
            JSONObject obj = new JSONObject(value);
            
            // this is still early since we probably didn't login yet so add the messages to the list of pending messages
            java.util.List<Message> pendingMessages = (java.util.List<Message>)Storage.getInstance().readObject("pendingMessages");
            if(pendingMessages == null) {
                pendingMessages = new ArrayList<>();
            }
            Message m = new Message(obj);
            pendingMessages.add(m);
            Storage.getInstance().writeObject("pendingMessages", pendingMessages);
            addMessage(m);
        } catch(JSONException err) {
            err.printStackTrace();
        }
    }
}
 
开发者ID:codenameone,项目名称:codenameone-demos,代码行数:22,代码来源:SocialChat.java


示例9: getItemAt

import com.codename1.io.Storage; //导入依赖的package包/类
public Image getItemAt(final int index) {
    if(images[index] == null) {
        images[index] = placeholder;
        Util.downloadUrlToStorageInBackground(IMAGE_URL_PREFIX + imageIds[index], "FullImage_" + imageIds[index], new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                try {
                    images[index] = EncodedImage.create(Storage.getInstance().createInputStream("FullImage_" + imageIds[index]));
                    listeners.fireDataChangeEvent(index, DataChangedListener.CHANGED);
                } catch(IOException err) {
                    err.printStackTrace();
                }
            }
        });
    } 
    return images[index];
}
 
开发者ID:codenameone,项目名称:codenameone-demos,代码行数:17,代码来源:PhotoShare.java


示例10: beforeMain

import com.codename1.io.Storage; //导入依赖的package包/类
@Override
protected void beforeMain(Form f) {
    Image icon = fetchResourceFile().getImage("shai_100x125.jpg");
    imageWidth = icon.getWidth();
    imageHeight = icon.getHeight();
    Container tasksContainer = findTasksContainer(f);
    tasksContainer.removeAll();
    todos = (Vector<Hashtable<String,String>>)Storage.getInstance().readObject("todos");
    if(todos == null) {
        todos = new Vector<Hashtable<String,String>>();
        return;
    }
    for(Hashtable<String,String> entry : todos) {
        MultiButton mb = createEntry(entry);
        tasksContainer.addComponent(mb);
    }
}
 
开发者ID:codenameone,项目名称:codenameone-demos,代码行数:18,代码来源:StateMachine.java


示例11: onMain_AddTaskButtonAction

import com.codename1.io.Storage; //导入依赖的package包/类
@Override
protected void onMain_AddTaskButtonAction(Component c, ActionEvent event) {
    TextField title = findTitleField(c.getParent());
    TextField description = findDescriptionField(c.getParent());
    Hashtable<String, String> entry = new Hashtable<String, String>();
    entry.put("title", title.getText());
    entry.put("description", description.getText());
    if(photo != null) {
        entry.put("photo", photo);
    }
    title.setText("");
    description.setText("");
    findCaptureButton(c.getParent()).setIcon(null);
    MultiButton mb = createEntry(entry);
    photo = null;
    todos.add(entry);
    Storage.getInstance().writeObject("todos", todos);        
    findTabs1(c.getParent()).setSelectedIndex(0);
    Container tasksContainer = findTasksContainer(c.getParent());
    tasksContainer.addComponent(mb);
    tasksContainer.animateLayout(500);
}
 
开发者ID:codenameone,项目名称:codenameone-demos,代码行数:23,代码来源:StateMachine.java


示例12: login

import com.codename1.io.Storage; //导入依赖的package包/类
public static void login(final Form form) {
    if (firstLogin()) {
        Login logForm = new Login(form);
        logForm.show();
    } else {
        //token exists no need to authenticate
        TOKEN = (String) Storage.getInstance().readObject("token");
        FaceBookAccess.setToken(TOKEN);
        //in case token has expired re-authenticate
        FaceBookAccess.getInstance().addResponseCodeListener(new ActionListener() {
            
            public void actionPerformed(ActionEvent evt) {
                NetworkEvent ne = (NetworkEvent) evt;
                int code = ne.getResponseCode();
                //token has expired
                if (code == 400) {
                    signIn(form);
                }                    
            }
        });
    }
}
 
开发者ID:codenameone,项目名称:codenameone-demos,代码行数:23,代码来源:Login.java


示例13: getImageData

import com.codename1.io.Storage; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
public byte[] getImageData() {
    if(data != null) {
        return data;
    }
    if(weak != null) {
        byte[] d = (byte[])Display.getInstance().extractHardRef(weak);
        if(d != null) {
            return d;
        }
    }
    byte[] imageData = (byte[])Storage.getInstance().readObject(fileName);
    if(keep) {
        data = imageData;
    } else {
        weak = Display.getInstance().createSoftWeakRef(imageData);
    }
    return imageData;
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:22,代码来源:StorageImage.java


示例14: getReceipts

import com.codename1.io.Storage; //导入依赖的package包/类
/**
 * Gets all of the receipts for this app.  Note:  You should periodically 
 * reload the receipts from the server to make sure that the user
 * hasn't canceled a receipt or renewed one.
 * @return List of receipts for purchases this app.
 */
public final List<Receipt> getReceipts() {
    synchronized (RECEIPTS_KEY) {
        if (receipts == null) {
            if (Storage.getInstance().exists(RECEIPTS_KEY)) {
                Receipt.registerExternalizable();
                try {
                    receipts = (List<Receipt>)Storage.getInstance().readObject(RECEIPTS_KEY);
                } catch (Exception ex) {
                    Log.p("Failed to load receipts from "+RECEIPTS_KEY);
                    Log.e(ex);
                    receipts = new ArrayList<Receipt>();
                    
                }
            } else {
                receipts = new ArrayList<Receipt>();
            }
        }
        return receipts;
    }
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:27,代码来源:Purchase.java


示例15: removePendingPurchase

import com.codename1.io.Storage; //导入依赖的package包/类
/**
 * Removes a receipt from pending purchases.
 * @param transactionId
 * @return 
 */
private Receipt removePendingPurchase(String transactionId) {
    synchronized(PENDING_PURCHASE_KEY) {
        Storage s = Storage.getInstance();
        List<Receipt> pendingPurchases = getPendingPurchases();
        Receipt found = null;
        for (Receipt r : pendingPurchases) {
            if (r.getTransactionId() != null && r.getTransactionId().equals(transactionId)) {
                found = r;
                break;
                
            }
        }
        if (found != null) {
            pendingPurchases.remove(found);
            s.writeObject(PENDING_PURCHASE_KEY, pendingPurchases);
            return found;
        } else {
            return null;
        }
    }
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:27,代码来源:Purchase.java


示例16: getPicture

import com.codename1.io.Storage; //导入依赖的package包/类
/**
 * Gets the picture of the given facebook object id
 *
 * @param id the object id to query
 * @param label place the image on the given label as an icon
 * @param toScale scale the image to the given dimension
 * @param tempStorage if true place the image in a temp storage
 */
public void getPicture(String id, final Label label, Dimension toScale, boolean tempStorage) throws IOException {
    checkAuthentication();

    FacebookRESTService fb = new FacebookRESTService(token, id, FacebookRESTService.PICTURE, false);
    if(toScale != null){
        fb.addArgument("width", "" + toScale.getWidth());
        fb.addArgument("height", "" + toScale.getHeight());
    }else{
        fb.addArgument("type", "small");
    }
    String cacheKey = id;
    //check if this image is a temporarey resource and it is not saved
    //already has a permanent image
    if (tempStorage && !Storage.getInstance().exists(id)) {
        cacheKey = TEMP_STORAGE + id;
    }
    ImageDownloadService.createImageToStorage(fb.requestURL(), label, cacheKey, toScale);
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:27,代码来源:FaceBookAccess.java


示例17: commit

import com.codename1.io.Storage; //导入依赖的package包/类
/**
 * Commit works synchronously and returns one of the return codes above to indicate 
 * the status. 
 * @return status code from the constants in this class
 */
public synchronized int commit() {
    if(storageQueue.size() > 0) { 
        if(CloudPersona.getCurrentPersona().getToken() == null) {
            CloudPersona.createAnonymous();
        }
        StorageRequest req = new StorageRequest();
        req.setContentType("multipart/form-data");
        req.setUrl(SERVER_URL + "/objStoreCommit");
        req.setPost(true);
        NetworkManager.getInstance().addToQueueAndWait(req);

        int i = req.getReturnCode();
        if(i == RETURN_CODE_SUCCESS) {
            storageQueue.clear();
            Storage.getInstance().deleteStorageFile("CN1StorageQueue");
        }
        return i;
    }
    return RETURN_CODE_EMPTY_QUEUE;
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:26,代码来源:CloudStorage.java


示例18: addCookie

import com.codename1.io.Storage; //导入依赖的package包/类
/**
 * Adds/replaces a cookie to be sent to the given domain
 * 
 * @param c cookie to add
 */
public void addCookie(Cookie c) {
    if(cookies == null){
        cookies = new Hashtable();
    }
    Hashtable h = (Hashtable)cookies.get(c.getDomain());
    if(h == null){
        h = new Hashtable();
        cookies.put(c.getDomain(), h);
    }
    h.put(c.getName(), c);
    if(Cookie.isAutoStored()){
        if(Storage.getInstance().exists(Cookie.STORAGE_NAME)){
            Storage.getInstance().deleteStorageFile(Cookie.STORAGE_NAME);
        }
        Storage.getInstance().writeObject(Cookie.STORAGE_NAME, cookies);
    }
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:23,代码来源:CodenameOneImplementation.java


示例19: removeCookiesForDomain

import com.codename1.io.Storage; //导入依赖的package包/类
protected final void removeCookiesForDomain(String domain) {
if(cookies == null || domain==null){
           return;
       }
       Hashtable h = (Hashtable)cookies.get(domain);
       if (h == null) {
           return;
       }
       h.clear();
       if(Cookie.isAutoStored()){
           if(Storage.getInstance().exists(Cookie.STORAGE_NAME)){
               Storage.getInstance().deleteStorageFile(Cookie.STORAGE_NAME);
           }
           Storage.getInstance().writeObject(Cookie.STORAGE_NAME, cookies);
       }
       
   }
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:18,代码来源:CodenameOneImplementation.java


示例20: testSerialization

import com.codename1.io.Storage; //导入依赖的package包/类
private void testSerialization() {
    System.out.println("============== testSerialization()");
    ParseGeoPoint geoPoint = new ParseGeoPoint(-32.4, 110.23);
    final String id = "geoPoint";
    
    assertTrue(Storage.getInstance().writeObject(id, geoPoint));

    Storage.getInstance().clearCache(); // Absolutely necessary to force retrieval from storage
    final ParseGeoPoint retrieved = (ParseGeoPoint)Storage.getInstance().readObject(id);
    
    assertEqual(geoPoint.getLatitude(), retrieved.getLatitude());
    assertEqual(geoPoint.getLongitude(), retrieved.getLongitude());
}
 
开发者ID:sidiabale,项目名称:parse4cn1,代码行数:14,代码来源:ParseGeoPointTest.java



注:本文中的com.codename1.io.Storage类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SortDirection类代码示例发布时间:2022-05-22
下一篇:
Java LabelElementFactory类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap