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

Java Util类代码示例

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

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



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


示例16: validateToken

import com.codename1.io.Util; //导入依赖的package包/类
/**
 * This method tries to validate the last access token if exists, if the 
 * last token is not valid anymore it will try to login the user in order to
 * get a fresh token
 * The method blocks until a valid token has been granted
 */ 
public void validateToken() throws IOException{
    String token = Preferences.get(Login.this.getClass().getName() + "Token", null);
    if(token == null){            
        throw new RuntimeException("No token to validate");
    }
    if(!validateToken(token)){
        callbackEnabled = false;
        doLogin();            
        Display.getInstance().invokeAndBlock(new Runnable() {

            public void run() {
                while(!callbackEnabled){
                    Util.sleep(100);
                }
            }
        });
        if(validateErr != null){
            throw new IOException(validateErr);
        }
    }
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:28,代码来源:Login.java


示例17: readResponse

import com.codename1.io.Util; //导入依赖的package包/类
protected void readResponse(InputStream input) throws IOException {
    //BufferedInputStream i = new BufferedInputStream(new InputStreamReader(input, ));
    BufferedInputStream i;
    if(input instanceof BufferedInputStream){
        i = (BufferedInputStream) input;
    }else{
        i = new BufferedInputStream(input);
    }
    i.setYield(-1);
    InputStreamReader reader = new InputStreamReader(i, "UTF-8");
    JSONParser.parse(reader, this);
    Util.cleanup(reader);
    if(stack.size() > 0){
        fireResponseListener(new NetworkEvent(this, stack.elementAt(0)));
    }
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:17,代码来源:FacebookRESTService.java


示例18: readResponse

import com.codename1.io.Util; //导入依赖的package包/类
protected void readResponse(InputStream input) throws IOException  {
    DataInputStream di = new DataInputStream(input);

    for(int iter = 0 ; iter  < objects.length ; iter++) {
        try {
            if(di.readBoolean()) {
                objects[iter].setLastModified(di.readLong());
                objects[iter].setValues((Hashtable)Util.readObject(di));
            }
            objects[iter].setStatus(CloudObject.STATUS_COMMITTED);
        } catch (IOException ex) {
            Log.e(ex);
        }
    }

    Util.cleanup(di);

    returnValue = RETURN_CODE_SUCCESS;
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:20,代码来源:CloudStorage.java


示例19: createColumnSortComparator

import com.codename1.io.Util; //导入依赖的package包/类
/**
 * Returns a generic comparator that tries to work in a way that will sort columns with similar object types.
 * This method can be overriden to create custom sort orders or return null and thus disable sorting for a 
 * specific column
 * 
 * @param column the column that's sorted
 * @return the comparator instance
 */
protected Comparator createColumnSortComparator(int column) {
    final CaseInsensitiveOrder ccmp = new CaseInsensitiveOrder();
    return new Comparator() {
        public int compare(Object o1, Object o2) {
            if(o1 instanceof String && o2 instanceof String) {
                return ccmp.compare((String)o1, (String)o2);
            }
            double d = Util.toDoubleValue(o1) - Util.toDoubleValue(o2);
            if(d > 0) {
                return 1;
            }
            if(d < 0) {
                return -1;
            }
            return 0;
        }
    };
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:27,代码来源:Table.java


示例20: runAndWait

import com.codename1.io.Util; //导入依赖的package包/类
/**
 * Invokes the given runnable on the thread and waits for its execution to complete
 * @param r the runnable
 */
public void runAndWait(final Runnable r) {
    final boolean[] flag = new boolean[1];
    synchronized(LOCK) {
        queue.add(new Runnable() {
            public void run() {
                r.run();
                synchronized(flag) {
                    flag[0] = true;
                    flag.notify();
                }
            }
        });
        LOCK.notify();
    }
    Display.getInstance().invokeAndBlock(new Runnable() {
        public void run() {
            synchronized(flag) {
                if(!flag[0]) {
                    Util.wait(flag);
                }
            }
        }
    });
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:29,代码来源:EasyThread.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java Define类代码示例发布时间:2022-05-22
下一篇:
Java ImageServlet类代码示例发布时间: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