private Object objectFromInputStreamInReentrantMode(InputStream is) throws IOException, ClassNotFoundException, InterruptedException { int len = is.available(); Object o = null; if (len != 0) { ExposedByteArrayOutputStream bytes = new ExposedByteArrayOutputStream(len); byte[] buf = new byte[Math.min(len, 1024)]; int bytesRead; while ((bytesRead = is.read(buf, 0, buf.length)) != -1) { bytes.write(buf, 0, bytesRead); } is = new ByteArrayInputStream(bytes.getRawBuffer(), 0, bytes.size()); ObjectInput unmarshaller = marshaller.startObjectInput(is, false); try { o = marshaller.objectFromObjectStream(unmarshaller); } finally { marshaller.finishObjectInput(unmarshaller); } } return o; }
public void testToStream() throws Exception { cs.store(TestInternalCacheEntryFactory.create("k1", "v1", -1, -1)); StreamingMarshaller marshaller = getMarshaller(); ByteArrayOutputStream out = new ByteArrayOutputStream(); ObjectOutput oo = marshaller.startObjectOutput(out, false, 12); try { cs.toStream(new UnclosableObjectOutputStream(oo)); } finally { marshaller.finishObjectOutput(oo); out.close(); } ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); ObjectInput oi = marshaller.startObjectInput(in, false); try { assert oi.readInt() == 1 : "we have 3 different buckets"; assert oi.readObject().equals(fcs.getLockFromKey("k1") + ""); assert oi.readInt() > 0; //size on disk } finally { marshaller.finishObjectInput(oi); } }
cs.fromStream(new UnclosableObjectInputStream(oi)); } finally { marshaller.finishObjectInput(oi);