List of usage examples for java.io ObjectInputStream read
public int read(byte[] buf, int off, int len) throws IOException
From source file:Main.java
public static void main(String[] args) throws Exception { byte[] cbuf = new byte[10]; FileOutputStream out = new FileOutputStream("test.txt"); ObjectOutputStream oout = new ObjectOutputStream(out); oout.writeUTF("Hello World from java2s.com"); oout.flush();/* w w w. j a va 2 s. c o m*/ oout.close(); ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt")); ois.read(cbuf, 0, 7); for (int i = 0; i < 7; i++) { System.out.print((char) cbuf[i]); } ois.close(); }
From source file:org.jactr.tools.async.message.ast.BaseASTMessage.java
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject();//from w w w.j av a2 s . c om boolean astIsNotNull = in.readBoolean(); if (astIsNotNull) { boolean wasCompressed = in.readBoolean(); if (wasCompressed) { /* * pull through GZIPInputStream. this can be done more effeciently.. */ int len = in.readInt(); byte[] bytes = _localInput.get(); if (bytes == null || bytes.length < len) { bytes = new byte[len]; _localInput.set(bytes); } if (LOGGER.isDebugEnabled()) LOGGER.debug("Reading " + len + " bytes to decompress"); in.read(bytes, 0, len); // in.readFully(bytes); ByteArrayInputStream bais = new ByteArrayInputStream(bytes, 0, len); DataInputStream zip = new DataInputStream(new GZIPInputStream(bais)); _ast = Serializer.read(zip); } else _ast = Serializer.read(in); } }
From source file:org.nuxeo.ecm.core.api.SerializableInputStream.java
private void readObject(ObjectInputStream in) throws ClassNotFoundException, IOException { // always perform the default de-serialization first in.defaultReadObject();//w ww.jav a 2s .c o m // create a temp file where we will put the blob content file = Framework.createTempFile("SerializableIS-", ".tmp"); Framework.trackFile(file, file); OutputStream out = null; try { out = new FileOutputStream(file); byte[] buffer = new byte[IN_MEM_LIMIT]; int read; int bytes = in.readInt(); while (bytes > -1 && (read = in.read(buffer, 0, bytes)) != -1) { out.write(buffer, 0, read); bytes -= read; if (bytes == 0) { bytes = in.readInt(); } } } finally { if (out != null) { out.close(); } if (file.isFile()) { this.in = new BufferedInputStream(new FileInputStream(file)); } } }