java.io.ObjectOutputStream#writeUnshared ( )源码实例Demo

下面列出了java.io.ObjectOutputStream#writeUnshared ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: samantha   文件: CacheInstanceRunnable.java
@Override
public void run() {
    try {
        ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream(cachePath));
        List<LearningInstance> instances;
        while ((instances = data.getLearningInstance()).size() > 0) {
            for (LearningInstance ins : instances) {
                cnt++;
                outputStream.writeUnshared(ins);
                outputStream.reset();
                if (cnt % 1000000 == 0) {
                    logger.info("Cached {} instances.", cnt);
                }
            }
        }
        outputStream.flush();
        outputStream.close();
    } catch (IOException e) {
        logger.error(e.getMessage());
        throw new BadRequestException(e);
    }
}
 
源代码2 项目: SFA   文件: SFATrie.java
/**
 * Java serialization
 *
 * @param o
 * @throws IOException
 */
private void writeObject(ObjectOutputStream o) throws IOException {
  o.defaultWriteObject();

  if (isLeaf()) {
    o.writeUnshared(elementIds.toArray());
  }
}
 
源代码3 项目: blazingcache   文件: JDKEntrySerializer.java
@Override
public byte[] serializeObject(String key, Object object) throws CacheException {
    try {
        ByteArrayOutputStream oo = new ByteArrayOutputStream();
        ObjectOutputStream oo2 = new ObjectOutputStream(oo);
        oo2.writeUnshared(object);
        oo2.close();
        return oo.toByteArray();
    } catch (IOException | SecurityException err) {
        throw new CacheException(err);
    }
}
 
源代码4 项目: blazingcache   文件: StandardKeySerializer.java
@Override
public String serialize(Object value) {
    if (value instanceof String) {
        // BlazingCache is made for string keys!
        // if you are not using strings then implement a custom serializer
        String key = (String) value;
        if (!key.startsWith("$")) {
            return key;
        }
    }
    try {
        ByteArrayOutputStream oo = new ByteArrayOutputStream();
        ObjectOutputStream o = new ObjectOutputStream(oo);
        o.writeUnshared(value);
        o.flush();
        return "$" + Base64.getEncoder().encodeToString(oo.toByteArray());
    } catch (java.io.NotSerializableException notSerializable) {
        // VERY BAD CASE (the TCK for instance), Usually keys are serializable or the client uses a custom serializer
        String alreadyCached = notSerializableKeys.get(value);
        if (alreadyCached != null) {
            return alreadyCached;
        }
        String id = value.getClass().getName() + "_" + System.identityHashCode(value);
        notSerializableKeys.put(value, id);
        return id;
    } catch (IOException err) {
        throw new CacheException(err);
    }
}
 
源代码5 项目: DeepDriver   文件: Fs.java
public static void writeObject2File(String file, Object obj) throws Exception {
	ObjectOutputStream oos = new ObjectOutputStream(
			new FileOutputStream(file));
	oos.writeUnshared(obj);
	oos.close();
}
 
源代码6 项目: DeepDriver   文件: Fs.java
public static void writeObj2FileWithTs(String file, Object obj) throws Exception {
	ObjectOutputStream oos = new ObjectOutputStream(
			new FileOutputStream(file));
	oos.writeUnshared(obj);
	oos.close();
}
 
源代码7 项目: SFA   文件: SFATrie.java
private void writeObject(ObjectOutputStream o) throws IOException {
  o.writeUnshared(word);
  o.writeUnshared(fourierValues);
  o.writeInt(pos);
}