@Override public B2CConverter run() throws IOException { return new B2CConverter(charset); } }
private Charset getCharset(String encoding) { if (encoding == null) { return DEFAULT_CHARSET; } try { return B2CConverter.getCharset(encoding); } catch (UnsupportedEncodingException e) { return DEFAULT_CHARSET; } }
/** Create a converter, with bytes going to a byte buffer */ public B2CConverter(String encoding) throws IOException { this.encoding=encoding; reset(); }
/** * Character conversion of the URI. * * @param uri MessageBytes object containing the URI * @param request The Servlet request object * @throws IOException if a IO exception occurs sending an error to the client */ protected void convertURI(MessageBytes uri, Request request) throws IOException { ByteChunk bc = uri.getByteChunk(); int length = bc.getLength(); CharChunk cc = uri.getCharChunk(); cc.allocate(length, -1); Charset charset = connector.getURICharset(); B2CConverter conv = request.getURIConverter(); if (conv == null) { conv = new B2CConverter(charset, true); request.setURIConverter(conv); } else { conv.recycle(); } try { conv.convert(bc, cc, true); uri.setChars(cc.getBuffer(), cc.getStart(), cc.getLength()); } catch (IOException ioe) { // Should never happen as B2CConverter should replace // problematic characters request.getResponse().sendError(HttpServletResponse.SC_BAD_REQUEST); } }
try { if (conv == null) { conv = new B2CConverter(enc); request.setURIConverter(conv); conv.convert(bc, cc, cc.getBuffer().length - cc.getEnd()); uri.setChars(cc.getBuffer(), cc.getStart(), cc.getLength());
/** Convert a buffer of bytes into a chars * @deprecated */ public void convert( ByteChunk bb, CharChunk cb ) throws IOException { // Set the ByteChunk as input to the Intermediate reader convert(bb, cb, cb.getBuffer().length - cb.getEnd()); }
/** * Recycle the output buffer. */ public void recycle() { state = INITIAL_STATE; // If usage of mark made the buffer too big, reallocate it if (cb.getChars().length > size) { cb = new CharChunk(size); cb.setLimit(size); cb.setOptimizedWrite(false); cb.setCharInputChannel(this); } else { cb.recycle(); } markPos = -1; bb.recycle(); closed = false; eof = false; if (conv != null) { conv.recycle(); } gotEnc = false; enc = null; readListener = null; }
/** * Recycle the output buffer. */ public void recycle() { state = INITIAL_STATE; // If usage of mark made the buffer too big, reallocate it if (cb.capacity() > size) { cb = CharBuffer.allocate(size); clear(cb); } else { clear(cb); } readLimit = size; markPos = -1; clear(bb); closed = false; if (conv != null) { conv.recycle(); encoders.get(conv.getCharset()).push(conv); conv = null; } }
/** * Character conversion of the URI. * * @param uri MessageBytes object containing the URI * @param request The Servlet request object * @throws IOException if a IO exception occurs sending an error to the client */ protected void convertURI(MessageBytes uri, Request request) throws IOException { ByteChunk bc = uri.getByteChunk(); int length = bc.getLength(); CharChunk cc = uri.getCharChunk(); cc.allocate(length, -1); Charset charset = connector.getURICharset(); B2CConverter conv = request.getURIConverter(); if (conv == null) { conv = new B2CConverter(charset, true); request.setURIConverter(conv); } else { conv.recycle(); } try { conv.convert(bc, cc, true); uri.setChars(cc.getBuffer(), cc.getStart(), cc.getLength()); } catch (IOException ioe) { // Should never happen as B2CConverter should replace // problematic characters request.getResponse().sendError(HttpServletResponse.SC_BAD_REQUEST); } }
try { if (conv == null) { conv = new B2CConverter(enc); request.setURIConverter(conv); conv.convert(bc, cc, cc.getBuffer().length - cc.getEnd()); uri.setChars(cc.getBuffer(), cc.getStart(), cc.getLength());
public int realReadChars() throws IOException { checkConverter(); boolean eof = false; if (bb.remaining() <= 0) { int nRead = realReadBytes(); if (nRead < 0) { eof = true; } } if (markPos == -1) { clear(cb); } else { // Make sure there's enough space in the worst case makeSpace(bb.remaining()); if ((cb.capacity() - cb.limit()) == 0 && bb.remaining() != 0) { // We went over the limit clear(cb); markPos = -1; } } state = CHAR_STATE; conv.convert(bb, cb, this, eof); if (cb.remaining() == 0 && eof) { return -1; } else { return cb.remaining(); } }
/** * Recycle the output buffer. */ public void recycle() { state = INITIAL_STATE; // If usage of mark made the buffer too big, reallocate it if (cb.getChars().length > size) { cb = new CharChunk(size); cb.setLimit(size); cb.setOptimizedWrite(false); cb.setCharInputChannel(this); } else { cb.recycle(); } markPos = -1; bb.recycle(); closed = false; eof = false; if (conv != null) { conv.recycle(); } gotEnc = false; enc = null; }
/** * Recycle the output buffer. */ public void recycle() { state = INITIAL_STATE; // If usage of mark made the buffer too big, reallocate it if (cb.capacity() > size) { cb = CharBuffer.allocate(size); clear(cb); } else { clear(cb); } readLimit = size; markPos = -1; clear(bb); closed = false; if (conv != null) { conv.recycle(); encoders.get(conv.getCharset()).push(conv); conv = null; } }
try { if (conv == null) { conv = new B2CConverter(enc); request.setURIConverter(conv); } else { conv.recycle(); conv.convert(bc, cc); uri.setChars(cc.getBuffer(), cc.getStart(), cc.getLength());
@Override public B2CConverter run() throws IOException { return new B2CConverter(charset); } }
try { if (conv == null) { conv = new B2CConverter(enc); request.setURIConverter(conv); conv.convert(bc, cc, cc.getBuffer().length - cc.getEnd()); uri.setChars(cc.getBuffer(), cc.getStart(), cc.getLength());
public int realReadChars() throws IOException { checkConverter(); boolean eof = false; if (bb.remaining() <= 0) { int nRead = realReadBytes(); if (nRead < 0) { eof = true; } } if (markPos == -1) { clear(cb); } else { // Make sure there's enough space in the worst case makeSpace(bb.remaining()); if ((cb.capacity() - cb.limit()) == 0 && bb.remaining() != 0) { // We went over the limit clear(cb); markPos = -1; } } state = CHAR_STATE; conv.convert(bb, cb, this, eof); if (cb.remaining() == 0 && eof) { return -1; } else { return cb.remaining(); } }
private Charset getCharset(String encoding) { if (encoding == null) { return DEFAULT_CHARSET; } try { return B2CConverter.getCharset(encoding); } catch (UnsupportedEncodingException e) { return DEFAULT_CHARSET; } }
/** * Recycle the output buffer. */ public void recycle() { state = INITIAL_STATE; bytesRead = 0; charsRead = 0; // If usage of mark made the buffer too big, reallocate it if(cb.getChars().length > size) { cb = new CharChunk(size); cb.setLimit(size); cb.setCharInputChannel(this); cb.setCharOutputChannel(this); } else { cb.recycle(); } markPos = -1; bb.recycle(); closed = false; if(conv != null) { conv.recycle(); } gotEnc = false; enc = null; }
/** Create a converter, with bytes going to a byte buffer */ public B2CConverter(String encoding) throws IOException { this.encoding=encoding; reset(); }