/** * Unescapes any double quotes in the given cookie value. * * @param bc The cookie value to modify */ public static void unescapeDoubleQuotes(final ByteChunk bc) { if (bc == null || bc.getLength() == 0) { return; } int src = bc.getStart(); int end = bc.getEnd(); int dest = src; final byte[] buffer = bc.getBuffer(); while (src < end) { if (buffer[src] == '\\' && src < end && buffer[src + 1] == '"') { src++; } buffer[dest] = buffer[src]; dest++; src++; } bc.setEnd(dest); }
/** Create a converter */ public C2BConverter(String encoding) throws IOException { this( new ByteChunk(1024), encoding ); }
/** * Compares the message data to the specified ByteChunk. * @param byteChunkToCheck the ByteChunk to compare * @return true if the comparison succeeded, false otherwise */ public boolean equals(final ByteChunk byteChunkToCheck) { return equals(byteChunkToCheck.getBuffer(), byteChunkToCheck.getStart(), byteChunkToCheck.getLength()); }
public static SettingsFrame fromBase64Uri(final DataChunk src) { if (src.getType() == DataChunk.Type.Bytes) { final ByteChunk bc = src.getByteChunk(); return parseBase64Uri(bc.getBuffer(), bc.getStart(), bc.getEnd()); } else if (src.getType() == DataChunk.Type.Buffer) { final BufferChunk bc = src.getBufferChunk(); return parseBase64Uri(bc.getBuffer(), bc.getStart(), bc.getEnd()); } return parseBase64Uri(src.toString()); }
/** Generate the bytes using the specified encoding */ public void convert(char c[], int off, int len) throws IOException { CharBuffer cb = CharBuffer.wrap(c, off, len); byte[] barr = bb.getBuffer(); int boff = bb.getEnd(); ByteBuffer tmp = ByteBuffer.wrap(barr, boff, barr.length - boff); CoderResult cr = encoder.encode(cb, tmp, true); bb.setEnd(tmp.position()); while (cr == CoderResult.OVERFLOW) { if (!bb.canGrow()) bb.flushBuffer(); boff = bb.getEnd(); barr = bb.getBuffer(); tmp = ByteBuffer.wrap(barr, boff, barr.length - boff); cr = encoder.encode(cb, tmp, true); bb.setEnd(tmp.position()); } if (cr != CoderResult.UNDERFLOW) { throw new IOException("Encoding error"); } }
/** Unimplemented yet. Do a char->byte conversion. */ public void toBytes() { if( ! byteC.isNull() ) { type=T_BYTES; return; } toString(); type=T_BYTES; byte bb[] = strValue.getBytes(byteC.getCharset()); byteC.setBytes(bb, 0, bb.length); }
/** * Returns true if the message bytes starts with the specified string. * @param c the character * @param starting The start position */ public int indexOf(char c, int starting) { int ret = indexOf( buff, start+starting, end, c); return (ret >= start) ? ret - start : -1; }
private void setBytesInternal(final byte[] array, final int position, final int limit) { byteChunk.setBytes(array, position, limit - position); switchToByteChunk(); }
/** * Returns the <tt>DataChunk</tt> end position. * * @return the <tt>DataChunk</tt> end position. */ @Override public int getEnd() { switch (type) { case Bytes: return byteChunk.getEnd(); case Buffer: return bufferChunk.getEnd(); case Chars: return charChunk.getEnd(); default: return stringValue.length(); } }
public void append( char c ) throws IOException { append( (byte)c); }
/** * Sets the <tt>DataChunk</tt> end position. * * @param end the <tt>DataChunk</tt> end position. */ @Override public void setEnd(int end) { switch (type) { case Bytes: byteChunk.setEnd(end); break; case Buffer: bufferChunk.setEnd(end); break; case Chars: charChunk.setEnd(end); break; default: break; } }
/** * Compares the message data to the specified ByteChunk. * @param byteChunkToCheck the ByteChunk to compare * @return true if the comparison succeeded, false otherwise */ public boolean equals(final ByteChunk byteChunkToCheck) { return equals(byteChunkToCheck.getBuffer(), byteChunkToCheck.getStart(), byteChunkToCheck.getLength()); }
public static SettingsFrame fromBase64Uri(final DataChunk src) { if (src.getType() == DataChunk.Type.Bytes) { final ByteChunk bc = src.getByteChunk(); return parseBase64Uri(bc.getBuffer(), bc.getStart(), bc.getEnd()); } else if (src.getType() == DataChunk.Type.Buffer) { final BufferChunk bc = src.getBufferChunk(); return parseBase64Uri(bc.getBuffer(), bc.getStart(), bc.getEnd()); } return parseBase64Uri(src.toString()); }
/** Generate the bytes using the specified encoding */ public void convert(char c[], int off, int len) throws IOException { CharBuffer cb = CharBuffer.wrap(c, off, len); byte[] barr = bb.getBuffer(); int boff = bb.getEnd(); ByteBuffer tmp = ByteBuffer.wrap(barr, boff, barr.length - boff); CoderResult cr = encoder.encode(cb, tmp, true); bb.setEnd(tmp.position()); while (cr == CoderResult.OVERFLOW) { if (!bb.canGrow()) bb.flushBuffer(); boff = bb.getEnd(); barr = bb.getBuffer(); tmp = ByteBuffer.wrap(barr, boff, barr.length - boff); cr = encoder.encode(cb, tmp, true); bb.setEnd(tmp.position()); } if (cr != CoderResult.UNDERFLOW) { throw new IOException("Encoding error"); } }
/** Unimplemented yet. Do a char->byte conversion. */ public void toBytes() { if( ! byteC.isNull() ) { type=T_BYTES; return; } toString(); type=T_BYTES; byte bb[] = strValue.getBytes(byteC.getCharset()); byteC.setBytes(bb, 0, bb.length); }
/** * Returns true if the message bytes starts with the specified string. * @param c the character * @param starting The start position */ public int indexOf(char c, int starting) { int ret = indexOf( buff, start+starting, end, c); return (ret >= start) ? ret - start : -1; }
private void setBytesInternal(final byte[] array, final int position, final int limit) { byteChunk.setBytes(array, position, limit - position); switchToByteChunk(); }