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


Java Util类代码示例

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


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

示例1: getDiskCache

import com.codename1.io.Util; //导入依赖的package包/类
/**
 * 
 */
private ArrayList<T> getDiskCache() throws IOException, JSONException{
    ArrayList<T> cacheArray = new ArrayList<>();
    
    InputStream fileStream = FileSystemStorage.getInstance().openInputStream(localCacheFile.getAbsolutePath());
    String fileContents = Util.readToString(fileStream);
    if(fileContents.length() > 1){
        JSONArray cacheJson = new JSONArray(fileContents);
        Log.p(this.getClass().getSimpleName() + ": Read " + cacheJson.length() + " entries from JSON cache", Log.INFO);

        for(int i = 0;i < cacheJson.length();i++){
            T obj = serializer.deserialize(cacheJson.getJSONObject(i));
            cacheArray.add(obj);
        }
    }else{
        Log.p(this.getClass().getSimpleName() + ": JSON cache empty", Log.INFO);
    }
    return cacheArray;
}
 
开发者ID:jegesh,项目名称:cn1-object-cacher,代码行数:22,代码来源:CacheFile.java

示例2: externalize

import com.codename1.io.Util; //导入依赖的package包/类
/**
 * @see com.codename1.io.Externalizable
 */
public void externalize(DataOutputStream out) throws IOException {
    /* 
    Note that ParseRelations are applied on ParseObjects and since only saved
    ParseObjects are serialized by design, the only piece of information 
    needed to reconstruct the relation is the targetClass. However,
    for completeness, we include other fields except the parent since
    serializing the parent will result in an infinite loop. If there's 
    ever a usecase where a ParseRelation is deemed useful outside a ParseObject,
    a smart way to store the parent would be implemented.
    */
    Util.writeUTF(targetClass, out);
    Util.writeUTF(key, out);
    Util.writeObject(setToArray(addedObjects), out);
    Util.writeObject(setToArray(removedObjects), out);
}
 
开发者ID:sidiabale,项目名称:parse4cn1,代码行数:19,代码来源:ParseRelation.java

示例3: addObjects

import com.codename1.io.Util; //导入依赖的package包/类
/**
 * Adds multiple objects to the batch to be {@link #execute() executed}.
 *
 * @param objects The objects to be added to the batch.
 * @param opType The type of operation to be performed on ALL
 * {@code objects}.
 * @return {@code this} to enable chaining.
 * @throws ParseException if any of the objects does not meet the
 * constraints for {@code opType}, for example, an objectId is required for
 * {@link EBatchOpType#UPDATE} and {@link EBatchOpType#DELETE} but should
 * not exist for {@link EBatchOpType#CREATE}. because it already has an
 * objectId.
 */
public ParseBatch addObjects(final Collection<? extends ParseObject> objects,
        final EBatchOpType opType) throws ParseException {

    final String urlPath =  StringUtil.replaceAll(Util.getURLPath(Parse.getApiEndpoint()), "/", "");
    final String pathPrefix = "/" + (!Parse.isEmpty(urlPath) ? urlPath + "/" : "");

    final String method = opTypeToHttpMethod(opType);
    
    for (ParseObject object : objects) {
        validate(object, opType);
        final JSONObject objData = new JSONObject();
        try {
            objData.put("method", method);
            objData.put("path", pathPrefix + getObjectPath(object, opType));
            objData.put("body", object.getParseData());
        } catch (JSONException ex) {
            throw new ParseException(ParseException.INVALID_JSON, 
                    ParseException.ERR_PREPARING_REQUEST, ex);
        }
        data.put(objData);
        parseObjects.add(object);
    }
    return this;
}
 
开发者ID:sidiabale,项目名称:parse4cn1,代码行数:38,代码来源:ParseBatch.java

示例4: internalize

import com.codename1.io.Util; //导入依赖的package包/类
/**
 * @see com.codename1.io.Externalizable
 */
public void internalize(int version, DataInputStream in) throws IOException {
    className = Util.readUTF(in);
    
    if (className != null) {
        parseObject = ParseObject.create(className);
        try {
            parseObject.internalize(version, in);
        } catch (ParseException ex) {
            Logger.getInstance().error(
                    "An error occurred while trying to deserialize ParseObject");
            throw new IOException(ex.getMessage());
        }
    } else {
       final String msg = "Unable to deserialize ParseObject "
               + "(null class name). Is class properly registered?";
       Logger.getInstance().error(msg); 
       throw new RuntimeException(msg);
    }
}
 
开发者ID:sidiabale,项目名称:parse4cn1,代码行数:23,代码来源:ExternalizableParseObject.java

示例5: externalize

import com.codename1.io.Util; //导入依赖的package包/类
/**
 * Serializes the contents of the ParseObject in a manner that complies with
 * the {@link com.codename1.io.Externalizable} interface.
 *
 * @param out The data stream to serialize to.
 * @throws IOException if any IO error occurs
 * @throws ParseException if the object is {@link #isDirty() dirty}
 */
public void externalize(DataOutputStream out) throws IOException, ParseException {
    if (isDirty()) {
        throw new ParseException(ParseException.OPERATION_FORBIDDEN,
                "A dirty ParseObject cannot be serialized to storage");
    }
    
    Util.writeUTF(getObjectId(), out);
    Util.writeObject(getCreatedAt(), out);
    Util.writeObject(getUpdatedAt(), out);
    
    // Persist actual data
    out.writeInt(keySet().size());
    for (String key : keySet()) {
        out.writeUTF(key);
        Object value = get(key);
        if (value instanceof ParseObject) {
            value = ((ParseObject)value).asExternalizable();
        } else if (ExternalizableJsonEntity.isExternalizableJsonEntity(value)) {
            value = new ExternalizableJsonEntity(value);
        }
        Util.writeObject(value, out);
    }
}
 
开发者ID:sidiabale,项目名称:parse4cn1,代码行数:32,代码来源:ParseObject.java

示例6: prepareUri

import com.codename1.io.Util; //导入依赖的package包/类
/**
 * Loop through the Map and use replace() to update the URL
 * according to the given parameters
 * @param uri
 * @param params
 * @return 
 */
private String prepareUri(String uri, Map<String, Object> params)
{
    if (params == null)
        params = new HashMap<String, Object>();

    for (Map.Entry entry : params.entrySet()) {
        String key = entry.getKey().toString();
        Object value = params.get(key);
       
        if (value instanceof Integer)
            value = value.toString();
        
        if (value instanceof String) {
            uri = StringUtil.replaceAll(uri, "{" + key + "}", Util.encodeUrl((String) value));
        }
    }

    return uri;
}
 
开发者ID:martijn00,项目名称:MusicPlayerCodenameOne,代码行数:27,代码来源:Api.java

示例7: internalize

import com.codename1.io.Util; //导入依赖的package包/类
@Override
public void internalize(int version, DataInputStream in) throws IOException {
    switch (version) {
        case 3:
            username = Util.readUTF(in);
            token = Util.readUTF(in);

            firstName = Util.readUTF(in);
            lastName =  Util.readUTF(in);
            languages = (ArrayList<String>)Util.readObject(in);
            break;
        case 2:
            firstName = Util.readUTF(in);
            lastName =  Util.readUTF(in);
            languages = (ArrayList<String>)Util.readObject(in);
            break;
    }
}
 
开发者ID:martijn00,项目名称:MusicPlayerCodenameOne,代码行数:19,代码来源:UserProfile.java

示例8: packHeader

import com.codename1.io.Util; //导入依赖的package包/类
private int packHeader(byte[] bytes, int offset) {
	try {
		BufferTools.stringIntoByteBuffer(TAG, 0, TAG.length(), bytes, offset);
	} catch (UnsupportedEncodingException e) {
	}
	String s[] = Util.split(version, ".");
	if (s.length > 0) {
		byte majorVersion = Byte.parseByte(s[0]);
		bytes[offset + MAJOR_VERSION_OFFSET] = majorVersion;
	}
	if (s.length > 1) {
		byte minorVersion = Byte.parseByte(s[1]);
		bytes[offset + MINOR_VERSION_OFFSET] = minorVersion;
	}
	packFlags(bytes, offset);
	BufferTools.packSynchsafeInteger(getDataLength(), bytes, offset + DATA_LENGTH_OFFSET);
	return offset + HEADER_LENGTH;
}
 
开发者ID:martijn00,项目名称:MusicPlayerCodenameOne,代码行数:19,代码来源:AbstractID3v2Tag.java

示例9: packFooter

import com.codename1.io.Util; //导入依赖的package包/类
private int packFooter(byte[] bytes, int offset) {
	try {
		BufferTools.stringIntoByteBuffer(FOOTER_TAG, 0, FOOTER_TAG.length(), bytes, offset);
	} catch (UnsupportedEncodingException e) {
	}
	String s[] = Util.split(version, ".");
	if (s.length > 0) {
		byte majorVersion = Byte.parseByte(s[0]);
		bytes[offset + MAJOR_VERSION_OFFSET] = majorVersion;
	}
	if (s.length > 1) {
		byte minorVersion = Byte.parseByte(s[1]);
		bytes[offset + MINOR_VERSION_OFFSET] = minorVersion;
	}
	packFlags(bytes, offset);
	BufferTools.packSynchsafeInteger(getDataLength(), bytes, offset + DATA_LENGTH_OFFSET);
	return offset + FOOTER_LENGTH;
}
 
开发者ID:martijn00,项目名称:MusicPlayerCodenameOne,代码行数:19,代码来源:AbstractID3v2Tag.java

示例10: getItemAt

import com.codename1.io.Util; //导入依赖的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

示例11: getVideoComponent

import com.codename1.io.Util; //导入依赖的package包/类
@Override
public Component getVideoComponent() {
    if (component == null) {
        if(uri != null) {
            moviePlayerPeer = nativeInstance.createVideoComponent(uri, onCompletionCallbackId);
            nativeInstance.setNativeVideoControlsEmbedded(moviePlayerPeer, embedNativeControls);
            component = PeerComponent.create(new long[] { nativeInstance.getVideoViewPeer(moviePlayerPeer) });
        } else {
            try {
                byte[] data = toByteArray(stream);
                Util.cleanup(stream);
                moviePlayerPeer = nativeInstance.createVideoComponent(data, onCompletionCallbackId);
                component = PeerComponent.create(new long[] { nativeInstance.getVideoViewPeer(moviePlayerPeer) });
            } catch (IOException ex) {
                ex.printStackTrace();
                return new Label("Error loading video " + ex);
            }
        }
    }
    return component;
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:22,代码来源:IOSImplementation.java

示例12: getSSLCertificates

import com.codename1.io.Util; //导入依赖的package包/类
private String[] getSSLCertificates(String url) {
    if (sslCertificates == null) {
        try {
            com.codename1.io.URL uUrl = new com.codename1.io.URL(url);
            String key = uUrl.getHost()+":"+uUrl.getPort();
            String certs = nativeInstance.getSSLCertificates(peer);
            if (certs == null) {
                if (sslCertificatesCache.containsKey(key)) {
                    sslCertificates = sslCertificatesCache.get(key);
                }
                if (sslCertificates == null) {
                    return new String[0];
                }
                return sslCertificates;
            }
            sslCertificates = Util.split(certs, ",");
            sslCertificatesCache.put(key, sslCertificates);
            return sslCertificates;
        } catch (Exception ex) {
            ex.printStackTrace();
            return new String[0];
        }
    }
    return sslCertificates;
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:26,代码来源:IOSImplementation.java

示例13: sendMessage

import com.codename1.io.Util; //导入依赖的package包/类
@Override
public void sendMessage(String[] recieptents, String subject, Message msg) {
    if(recieptents != null){
        try {
            String mailto = "mailto:" + recieptents[0];
            for(int iter = 1 ; iter < recieptents.length ; iter++) {
                mailto += "," + recieptents[iter];
            }
            mailto += "?body=" + Util.encodeUrl(msg.getContent()) + "&subject=" + Util.encodeUrl(subject);
            Desktop.getDesktop().mail(new URI(mailto));
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        System.out.println("sending message to " + recieptents[0]);
    }
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:17,代码来源:JavaSEPort.java

示例14: onMessage

import com.codename1.io.Util; //导入依赖的package包/类
public static void onMessage(final PushInputStream stream, final StreamConnection sc) {
    if(pushCallback != null) {
        new Thread() {
            public void run() {
                try {
                    final byte[] buffer = Util.readInputStream(stream);
                    try {
                        stream.accept();
                        Util.cleanup(stream);
                        sc.close();
                    } catch(Throwable t) {}
                    updateIndicator(unreadCount + 1);
                    Display.getInstance().callSerially(new Runnable() {
                        public void run() {
                            pushCallback.push(new String(buffer));
                        }
                    });
                } catch(IOException err) {
                    err.printStackTrace();
                }
            }
        }.start();
    }
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:25,代码来源:BlackBerryOS5Implementation.java

示例15: externalize

import com.codename1.io.Util; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
public void externalize(DataOutputStream out) throws IOException {
    Map m = new HashMap();
    m.put("sku", getSku());
    m.put("expiryDate", getExpiryDate());
    m.put("cancellationDate", getCancellationDate());
    m.put("purchaseDate", getPurchaseDate());
    m.put("orderData", getOrderData());
    m.put("transactionId", getTransactionId());
    m.put("quantity", getQuantity());
    m.put("storeCode", getStoreCode());
    m.put("internalId", getInternalId());

    Util.writeObject(m, out);
    
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:19,代码来源:Receipt.java


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