Java 8 Externalizable - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Externalizable class.

This code example shows how to use the following methods:writeExternal
  public static final long WEEK   = DAY * 7;
 
  public static byte[] toStream(Externalizable iSource) throws IOException {
    final ByteArrayOutputStream stream = new ByteArrayOutputStream();
    final ObjectOutputStream oos = new ObjectOutputStream(stream);
    iSource.writeExternal(oos);
    oos.flush();
    stream.flush();
    return stream.toByteArray();
  } 
 
  public static long getTimeAsMillisecs(final Object iSize) {
    if (iSize == null)
      throw new IllegalArgumentException("Time is null");
 
    if (iSize instanceof Number)
      // MILLISECS 
      return ((Number) iSize).longValue();
 
    String time = iSize.toString();
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:writeExternal
    } 
 
    @Override 
    public void write(Excerpt bytes, @NotNull E e) {
        try { 
            e.writeExternal(bytes);
        } catch (IOException e2) {
            throw new IllegalStateException(e2);
        } 
    } 
 
    @Override 
    public E read(Excerpt bytes) {
        E e;
        try { 
            e = (E) UnsafeExcerpt.UNSAFE.allocateInstance(classMarshaled);
            e.readExternal(bytes);
        } catch (Exception e2) {
            throw new IllegalStateException(e2);
        } 
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:close, readObject
This code example shows how to use the following methods:readObject
	/** 
	 * Reads the input stream and deserializes into an object. 
	 */ 
	@Override 
	public Object deserialize(InputStream inputStream) throws IOException {
		ObjectInputStream objectInputStream = new ObjectInputStream(inputStream);
		try { 
			return objectInputStream.readObject();
		} 
		catch (ClassNotFoundException ex) {
			throw new NestedIOException("Failed to deserialize object type", ex);
		} 
	} 
 
} 
10
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:available, close, readObject
        try { 
            ByteBuffer dup = bytes.duplicate();
            int l = dup.remaining();
            ByteArrayInputStream bais = new ByteArrayInputStream(dup.array(),
                    dup.arrayOffset() + dup.position(), l);
            ObjectInputStream ois = new ObjectInputStream(bais);
            Object obj = ois.readObject();
            dup.position(dup.position() + (l - ois.available()));
            ois.close();
            return obj; 
        } catch (Exception ex) {
            throw new SerializationException(ex);
        } 
    } 
 
    public static ObjectSerializer get() { 
        return INSTANCE;
    } 
} 
10
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:close, readObject
This code example shows how to use the following methods:readObject
		oos.flush();
		baos.flush();
		byte[] bytes = baos.toByteArray();
 
		ByteArrayInputStream is = new ByteArrayInputStream(bytes);
		ObjectInputStream ois = new ObjectInputStream(is);
		Object o2 = ois.readObject();
		return o2; 
	} 
 
} 
10
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:close, readObject
            final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
            final ObjectOutput out = new ObjectOutputStream(buffer);
            out.writeObject(t1);
            out.close();
 
            final ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
            t2 = (StandardGradientPaintTransformer) in.readObject();
            in.close();
        } 
        catch (Exception e) {
            System.out.println(e.toString());
        } 
        assertTrue(t1.equals(t2)); 
 
    } 
 
} 
10
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:readObject
	public static Object deserialize(byte[] bytes) {
		if (bytes == null) {
			return null; 
		} 
		try { 
			ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes));
			return ois.readObject();
		} 
		catch (IOException ex) {
			throw new IllegalArgumentException("Failed to deserialize object", ex);
		} 
		catch (ClassNotFoundException ex) {
			throw new IllegalStateException("Failed to deserialize object type", ex);
		} 
	} 
 
} 
10
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:close, readObject
See Code Examples for Java 8 Externalizable Methods: