/** {@inheritDoc} */ public void writeByte(final int v) throws IOException { try { final byte[] buffer = this.buffer; final int remaining = buffer.length - position; if (remaining == 0) { flush(); buffer[0] = (byte) v; position = 1; } else { buffer[position++] = (byte) v; } } catch (NullPointerException e) { throw notActiveException(); } }
/** {@inheritDoc} */ public void write(final byte[] bytes) throws IOException { write(bytes, 0, bytes.length); }
/** {@inheritDoc} */ public void writeChars(final String s) throws IOException { final int len = s.length(); for (int i = 0; i < len; i ++) { writeChar(s.charAt(i)); } }
/** * Finish writing to a stream. The stream is released. * No further writing may be done until the {@link #start(ByteOutput)} method is again invoked. * * @throws IOException if an error occurs */ protected void finish() throws IOException { try { flush(); } finally { buffer = null; byteOutput = null; } }
/** {@inheritDoc} */ public void writeUTF(final String s) throws IOException { writeShort(UTFUtils.getShortUTFLength(s)); UTFUtils.writeUTFBytes(this, s); }
int version = this.context.getCurrentVersion(); ByteArrayOutputStream output = new ByteArrayOutputStream(); SimpleDataOutput data = new SimpleDataOutput(Marshalling.createByteOutput(output)); data.writeInt(version); Marshaller marshaller = this.context.createMarshaller(version); try {
byte[] getBytes() throws IOException { byte[] bytes = this.bytes; if (bytes != null) return bytes; if (this.object == null) return null; int version = this.context.getCurrentVersion(); ByteArrayOutputStream output = new ByteArrayOutputStream(); ClassLoader loader = setThreadContextClassLoader(this.context.getClassLoader()); try (SimpleDataOutput data = new SimpleDataOutput(Marshalling.createByteOutput(output))) { IndexSerializer.VARIABLE.writeInt(data, version); try (Marshaller marshaller = this.context.createMarshaller(version)) { marshaller.start(data); marshaller.writeObject(this.object); marshaller.finish(); return output.toByteArray(); } } finally { setThreadContextClassLoader(loader); } }
public void writeInt(int v) throws IOException { output.writeInt(v); }
public void close() throws IOException { output.close(); }
public void writeBoolean(boolean v) throws IOException { output.writeBoolean(v); }
/** * {@inheritDoc} */ public void close() throws IOException { flush(); byteOutput.close(); } }
public void writeShort(int v) throws IOException { output.writeShort(v); }
@Override public void store(V obj) { File file = getFile(obj.getId()); log.tracef("Storing state to %s", file); try { FileOutputStream outputStream = null; try { outputStream = FOSAction.open(file); SimpleDataOutput output = new SimpleDataOutput(Marshalling.createByteOutput(outputStream)); int version = this.passivationManager.getCurrentMarshallingVersion(); output.writeInt(version); MarshallingConfiguration config = this.passivationManager.getMarshallingConfiguration(version); Marshaller marshaller = this.marshallerFactory.createMarshaller(config); marshaller.start(output); try { marshaller.writeObject(obj); marshaller.finish(); } finally { marshaller.close(); } } finally { safeClose(outputStream); } } catch (IOException e) { throw EjbMessages.MESSAGES.passivationFailed(e, obj.getId()); } }
public SimpleByteDataOutput(final OutputStream outputStream) { this.output = new SimpleDataOutput(Marshalling.createByteOutput(outputStream)); }
public void writeInt(int v) throws IOException { output.writeInt(v); }
public void close() throws IOException { output.close(); }
public void writeBoolean(boolean v) throws IOException { output.writeBoolean(v); }
/** {@inheritDoc} */ public void writeBoolean(final boolean v) throws IOException { try { final byte[] buffer = this.buffer; final int remaining = buffer.length - position; if (remaining == 0) { flush(); buffer[0] = (byte) (v ? 1 : 0); position = 1; } else { buffer[position++] = (byte) (v ? 1 : 0); } } catch (NullPointerException e) { throw notActiveException(); } }
/** {@inheritDoc} */ public void writeBytes(final String s) throws IOException { final int len = s.length(); for (int i = 0; i < len; i ++) { write(s.charAt(i)); } }
/** {@inheritDoc} */ public void write(final byte[] bytes, final int off, int len) throws IOException { final int bl = buffer.length; final int position = this.position; if (len > bl - position || len > bl >> 3) { flush(); byteOutput.write(bytes, off, len); } else { System.arraycopy(bytes, off, buffer, position, len); this.position = position + len; } }