Java Code Examples for java.io.ObjectOutputStream#writeUnshared()

The following examples show how to use java.io.ObjectOutputStream#writeUnshared() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: samantha   File: CacheInstanceRunnable.java    License: MIT License 6 votes vote down vote up
@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);
    }
}
 
Example 2
Source Project: SFA   File: SFATrie.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Java serialization
 *
 * @param o
 * @throws IOException
 */
private void writeObject(ObjectOutputStream o) throws IOException {
  o.defaultWriteObject();

  if (isLeaf()) {
    o.writeUnshared(elementIds.toArray());
  }
}
 
Example 3
Source Project: blazingcache   File: JDKEntrySerializer.java    License: Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example 4
@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);
    }
}
 
Example 5
Source Project: DeepDriver   File: Fs.java    License: Apache License 2.0 4 votes vote down vote up
public static void writeObject2File(String file, Object obj) throws Exception {
	ObjectOutputStream oos = new ObjectOutputStream(
			new FileOutputStream(file));
	oos.writeUnshared(obj);
	oos.close();
}
 
Example 6
Source Project: DeepDriver   File: Fs.java    License: Apache License 2.0 4 votes vote down vote up
public static void writeObj2FileWithTs(String file, Object obj) throws Exception {
	ObjectOutputStream oos = new ObjectOutputStream(
			new FileOutputStream(file));
	oos.writeUnshared(obj);
	oos.close();
}
 
Example 7
Source Project: SFA   File: SFATrie.java    License: GNU General Public License v3.0 4 votes vote down vote up
private void writeObject(ObjectOutputStream o) throws IOException {
  o.writeUnshared(word);
  o.writeUnshared(fourierValues);
  o.writeInt(pos);
}