private void writeObject(ObjectOutputStream out) throws IOException { // TODO: better size estimation byte[] buf = new byte[1024]; int n; while (true) try { n = marshal(buf, 0); break; } catch (BufferUnderflowException e) { buf = new byte[4 * buf.length]; } out.writeInt(n); out.write(buf, 0, n); }
private void writeObject(ObjectOutputStream out) throws IOException { // TODO: better size estimation byte[] buf = new byte[1024]; int n; while (true) try { n = marshal(buf, 0); break; } catch (BufferUnderflowException e) { buf = new byte[4 * buf.length]; } out.writeInt(n); out.write(buf, 0, n); }
/** * Serializes the object. * @param out the data destination. * @param buf the initial buffer or {@code null}. * @return the final buffer. When the serial fits into {@code buf} then the return is {@code buf}. * Otherwise the return is a new buffer, large enough to hold the whole serial. * @throws IOException from {@code out}. * @throws IllegalStateException on an upper limit breach defined by {@link #colferSizeMax}. */ public byte[] marshal(OutputStream out, byte[] buf) throws IOException { // TODO: better size estimation if (buf == null || buf.length == 0) buf = new byte[Math.min(Span.colferSizeMax, 2048)]; while (true) { int i; try { i = marshal(buf, 0); } catch (BufferOverflowException e) { buf = new byte[Math.min(Span.colferSizeMax, buf.length * 4)]; continue; } out.write(buf, 0, i); return buf; } }
/** * Serializes the object. * @param out the data destination. * @param buf the initial buffer or {@code null}. * @return the final buffer. When the serial fits into {@code buf} then the return is {@code buf}. * Otherwise the return is a new buffer, large enough to hold the whole serial. * @throws IOException from {@code out}. * @throws IllegalStateException on an upper limit breach defined by {@link #colferSizeMax}. */ public byte[] marshal(OutputStream out, byte[] buf) throws IOException { // TODO: better size estimation if (buf == null || buf.length == 0) buf = new byte[Math.min(Span.colferSizeMax, 2048)]; while (true) { int i; try { i = marshal(buf, 0); } catch (BufferOverflowException e) { buf = new byte[Math.min(Span.colferSizeMax, buf.length * 4)]; continue; } out.write(buf, 0, i); return buf; } }