@Override public void close() throws IOException { in.close(); }
@Override public int read() throws IOException { if (remaining-->0) { return in.read(); } return -1; }
void clearRemaining() throws IOException { while (remaining > 0) { long skipped = in.skip(remaining); if (skipped == 0) { break; } remaining -= skipped; } }
int available = Math.min(remaining, in.getCount() - in.getPosition()); if (available > 0) { this.stream.write(in.getBuffer(), in.getPosition(), available); in.setPosition(in.getPosition() + available); remaining -= available; ObjectConverterUtil.write(this.stream, in, in.getBuffer(), remaining, false); remaining = 0;
private OioObjectChannel(Socket socket, int maxObjectSize) throws IOException { log.fine("creating new OioObjectChannel"); //$NON-NLS-1$ this.socket = socket; DataOutputStream out = new DataOutputStream(socket.getOutputStream()); outputStream = new ObjectEncoderOutputStream(out, STREAM_BUFFER_SIZE); final ClassLoader cl = this.getClass().getClassLoader(); inputStream = new ObjectDecoderInputStream(new AccessibleBufferedInputStream(socket.getInputStream(), STREAM_BUFFER_SIZE), cl, maxObjectSize); }
int available = Math.min(remaining, in.getCount() - in.getPosition()); if (available > 0) { this.stream.write(in.getBuffer(), in.getPosition(), available); in.setPosition(in.getPosition() + available); remaining -= available; ObjectConverterUtil.write(this.stream, in, in.getBuffer(), remaining, false); remaining = 0;
private OioObjectChannel(Socket socket, int maxObjectSize) throws IOException { log.fine("creating new OioObjectChannel"); //$NON-NLS-1$ this.socket = socket; DataOutputStream out = new DataOutputStream(socket.getOutputStream()); outputStream = new ObjectEncoderOutputStream(out, STREAM_BUFFER_SIZE); final ClassLoader cl = this.getClass().getClassLoader(); inputStream = new ObjectDecoderInputStream(new AccessibleBufferedInputStream(socket.getInputStream(), STREAM_BUFFER_SIZE), cl, maxObjectSize); }
@Test public void testReplaceObject() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectEncoderOutputStream out = new ObjectEncoderOutputStream(new DataOutputStream(baos), 512); ClobImpl clob = new ClobImpl(new InputStreamFactory() { @Override public InputStream getInputStream() throws IOException { return new ReaderInputStream(new StringReader("Clob contents"), Charset.forName(Streamable.ENCODING)); //$NON-NLS-1$ } }, -1); out.writeObject(clob); ObjectDecoderInputStream in = new ObjectDecoderInputStream(new AccessibleBufferedInputStream(new ByteArrayInputStream(baos.toByteArray()), 1024), Thread.currentThread().getContextClassLoader(), 1024); Object result = in.readObject(); assertTrue(result instanceof ClobImpl); } }
@Override public int read() throws IOException { if (remaining-->0) { return in.read(); } return -1; }
void clearRemaining() throws IOException { while (remaining > 0) { long skipped = in.skip(remaining); if (skipped == 0) { break; } remaining -= skipped; } }
@Override public void close() throws IOException { in.close(); }
@Test public void testTimeoutException() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectEncoderOutputStream oeos = new ObjectEncoderOutputStream(new DataOutputStream(baos), 512); List<Integer> obj = Arrays.asList(1, 2, 3); oeos.writeObject(obj); oeos.close(); final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); InputStream is = new InputStream() { int count; @Override public int read() throws IOException { if (count++%2==0) { throw new SocketTimeoutException(); } return bais.read(); } }; ObjectDecoderInputStream odis = new ObjectDecoderInputStream(new AccessibleBufferedInputStream(is, 1024), Thread.currentThread().getContextClassLoader(), 1024); Object result = null; do { try { result = odis.readObject(); } catch (IOException e) { } } while (result == null); assertEquals(obj, result); }
@Override public int read(byte[] b, int off, int len) throws IOException { if (remaining <= 0) { return -1; } int read = in.read(b, off, Math.min(len, remaining)); if (read > 0) { remaining -= read; } return read; } };
@Override public int read(byte[] b, int off, int len) throws IOException { if (remaining <= 0) { return -1; } int read = in.read(b, off, Math.min(len, remaining)); if (read > 0) { remaining -= read; } return read; } };