/** Compact this {@link SSHPacket} */ public void compact() { if (available() > 0) System.arraycopy(data, rpos, data, 0, wpos - rpos); wpos -= rpos; rpos = 0; }
public byte[] getCompactData() { final int len = available(); if (len > 0) { byte[] b = new byte[len]; System.arraycopy(data, rpos, b, 0, len); return b; } else return new byte[0]; }
protected void ensureAvailable(int a) throws BufferException { if (available() < a) { throw new BufferException("Underflow"); } }
/** * Copies the contents of provided buffer into this buffer * * @param buffer the {@code Buffer} to copy * * @return this */ @SuppressWarnings("unchecked") public T putBuffer(Buffer<? extends Buffer<?>> buffer) { if (buffer != null) { int r = buffer.available(); ensureCapacity(r); System.arraycopy(buffer.data, buffer.rpos, data, wpos, r); wpos += r; } return (T) this; }
private static List<String> unpackList(byte[] packedString) throws BufferException { List<String> list = new ArrayList<String>(); Buffer<?> buf = new Buffer.PlainBuffer(packedString); while (buf.available() > 0) { list.add(buf.readString()); } return list; }
private static Map<String, String> unpackMap(byte[] packedString) throws BufferException { Map<String, String> map = new LinkedHashMap<String, String>(); Buffer<?> buf = new Buffer.PlainBuffer(packedString); while (buf.available() > 0) { String name = buf.readString(); String data = unpackString(buf.readStringAsBytes()); map.put(name, data); } return map; }
/** * Gives a readable snapshot of the buffer in hex. This is useful for debugging. * * @return snapshot of the buffer as a hex string with each octet delimited by a space */ public String printHex() { return ByteArrayUtils.printHex(array(), rpos(), available()); }
@Override public void uncompress(Buffer from, Buffer to) throws TransportException { inflater.setNextIn(from.array()); inflater.setNextInIndex(from.rpos()); inflater.setAvailIn(from.available()); while (true) { inflater.setNextOut(tempBuf); inflater.setNextOutIndex(0); inflater.setAvailOut(BUF_SIZE); final int status = inflater.inflate(JZlib.Z_PARTIAL_FLUSH); switch (status) { case JZlib.Z_OK: to.putRawBytes(tempBuf, 0, BUF_SIZE - inflater.getAvailOut()); break; case JZlib.Z_BUF_ERROR: return; default: throw new TransportException(DisconnectReason.COMPRESSION_ERROR, "uncompress: inflate returned " + status); } } }
@Override public void compress(Buffer buffer) { deflater.setNextIn(buffer.array()); deflater.setNextInIndex(buffer.rpos()); deflater.setAvailIn(buffer.available()); buffer.wpos(buffer.rpos()); do { deflater.setNextOut(tempBuf); deflater.setNextOutIndex(0); deflater.setAvailOut(BUF_SIZE); final int status = deflater.deflate(JZlib.Z_PARTIAL_FLUSH); if (status == JZlib.Z_OK) { buffer.putRawBytes(tempBuf, 0, BUF_SIZE - deflater.getAvailOut()); } else { throw new SSHRuntimeException("compress: deflate returned " + status); } } while (deflater.getAvailOut() == 0); }
public byte[] getCompactData() { final int len = available(); if (len > 0) { byte[] b = new byte[len]; System.arraycopy(data, rpos, b, 0, len); return b; } else return new byte[0]; }
/** Compact this {@link SSHPacket} */ public void compact() { if (available() > 0) System.arraycopy(data, rpos, data, 0, wpos - rpos); wpos -= rpos; rpos = 0; }
public byte[] getCompactData() { final int len = available(); if (len > 0) { byte[] b = new byte[len]; System.arraycopy(data, rpos, b, 0, len); return b; } else return new byte[0]; }
/** Compact this {@link SSHPacket} */ public void compact() { System.err.println("COMPACTING"); if (available() > 0) System.arraycopy(data, rpos, data, 0, wpos - rpos); wpos -= rpos; rpos = 0; }
protected void ensureAvailable(int a) throws BufferException { if (available() < a) throw new BufferException("Underflow"); }
protected void ensureAvailable(int a) throws BufferException { if (available() < a) { throw new BufferException("Underflow"); } }
/** * Copies the contents of provided buffer into this buffer * * @param buffer the {@code Buffer} to copy * * @return this */ @SuppressWarnings("unchecked") public T putBuffer(Buffer<? extends Buffer<?>> buffer) { if (buffer != null) { int r = buffer.available(); ensureCapacity(r); System.arraycopy(buffer.data, buffer.rpos, data, wpos, r); wpos += r; } return (T) this; }
private static List<String> unpackList(byte[] packedString) throws BufferException { List<String> list = new ArrayList<String>(); Buffer<?> buf = new Buffer.PlainBuffer(packedString); while (buf.available() > 0) { list.add(buf.readString()); } return list; }
private static Map<String, String> unpackMap(byte[] packedString) throws BufferException { Map<String, String> map = new LinkedHashMap<String, String>(); Buffer<?> buf = new Buffer.PlainBuffer(packedString); while (buf.available() > 0) { String name = buf.readString(); String data = unpackString(buf.readStringAsBytes()); map.put(name, data); } return map; }
/** * Gives a readable snapshot of the buffer in hex. This is useful for debugging. * * @return snapshot of the buffer as a hex string with each octet delimited by a space */ public String printHex() { return ByteArrayUtils.printHex(array(), rpos(), available()); }
/** * Gives a readable snapshot of the buffer in hex. This is useful for debugging. * * @return snapshot of the buffer as a hex string with each octet delimited by a space */ public String printHex() { return ByteArrayUtils.printHex(array(), rpos(), available()); }