当前位置: 首页>>代码示例>>Java>>正文


Java Storage类代码示例

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


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


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