public synchronized byte[] readMessage() throws IOException { if (!hasMoreInput()) return null; readBuffer.reset(); copyTo(readBuffer); return readBuffer.toByteArray(); }
public synchronized int copyTo(OutputStream out) throws IOException { if (eom) throw new IllegalStateException(); int totlen = 0; int remaining; int leftover = 0; while ((remaining = remaining(count)) == -1) { int avail = count - pos; out.write(buf, pos - leftover, avail + leftover); totlen += avail + leftover; pos = count; if (read() == -1) return totlen; leftover = 1; } out.write(buf, pos - leftover, remaining + leftover); totlen += remaining + leftover; pos += remaining + 1; eom(); return totlen; }
public MLLPConnection(Socket sock) throws IOException { this.sock = sock; mllpIn = new MLLPInputStream(sock.getInputStream()); mllpOut = new MLLPOutputStream(sock.getOutputStream()); }
@Override public synchronized int read() throws IOException { if (eom) return -1; int b = super.read(); if (b == -1) throw new EOFException(); if (b != EOM1) return b; eom(); return -1; }
public byte[] readMessage() throws IOException { byte[] b = mllpIn.readMessage(); if (b != null) log("{} >> {}", b, 0, b.length); return b; }
public MLLPConnection(Socket sock, int bufferSize) throws IOException { this.sock = sock; mllpIn = new MLLPInputStream(sock.getInputStream()); mllpOut = new MLLPOutputStream(new BufferedOutputStream(sock.getOutputStream(), bufferSize)); }
@Override public synchronized int read(byte[] b, int off, int len) throws IOException { if (b == null) throw new NullPointerException(); if (off < 0 || len < 0 || len > b.length - off) throw new IndexOutOfBoundsException(); if (eom) return -1; if (len == 0) return 0; if (read() == -1) return -1; int rlen = Math.min(count - pos, len-1); int remaining = remaining(pos + rlen); if (remaining == -1) { System.arraycopy(buf, pos-1, b, off, rlen+1); pos += rlen; return rlen+1; } System.arraycopy(buf, pos-1, b, off, remaining+1); pos += remaining+1; eom(); return remaining + 1; }