public void recycle() { originalRequestURIDC.recycle(); decodedRequestURIDC.recycle(); requestURIDC.recycle(); isDecoded = false; wasSlashAllowed = true; wasBackSlashAllowed = true; decodedURIEncoding = null; defaultURIEncoding = UTF8_CHARSET; }
public String getDecodedURI( final boolean isSlashAllowed, final boolean isBackSlashAllowed, Charset encoding) throws CharConversionException { getDecodedRequestURIBC(isSlashAllowed, isBackSlashAllowed, encoding); return decodedRequestURIDC.toString(); }
public DataChunk getDecodedRequestURIBC( final boolean isSlashAllowed, final boolean isBackSlashAllowed, final Charset charset) throws CharConversionException { if (isDecoded && isSlashAllowed == wasSlashAllowed && isBackSlashAllowed == wasBackSlashAllowed && charset == decodedURIEncoding) { return decodedRequestURIDC; } checkDecodedURICapacity(requestURIDC.getLength()); decodedRequestURIDC.setBytes(preallocatedDecodedURIBuffer); HttpRequestURIDecoder.decode( requestURIDC, decodedRequestURIDC, isSlashAllowed, isBackSlashAllowed, charset); isDecoded = true; wasSlashAllowed = isSlashAllowed; wasBackSlashAllowed = isBackSlashAllowed; decodedURIEncoding = charset; return decodedRequestURIDC; }
public void init(final byte[] input, final int start, final int end) { originalRequestURIDC.setBytes(input, start, end); requestURIDC.setBytes(input, start, end); }
public void init(final Buffer input, final int start, final int end) { originalRequestURIDC.setBuffer(input, start, end); requestURIDC.setBuffer(input, start, end); }
/** * Request URI holder. Contains 3 types of URI: 1) Original, which represents the URI's original * state at time it was set. 2) Decoded, which has represents URI after being URI and String decoded * (internally used by Mapper). 3) Actual, which is supposed as URI value returned to user. * * @author Alexey Stashok */ public class RequestURIRef { private boolean isDecoded; private Charset decodedURIEncoding; private boolean wasSlashAllowed = true; private boolean wasBackSlashAllowed = true; private Charset defaultURIEncoding = UTF8_CHARSET; // Original Request URI private final DataChunk originalRequestURIDC = DataChunk.newInstance(); // Actual Request URI private final DataChunk requestURIDC = new DataChunk() { @Override public void notifyDirectUpdate() { if (type == Type.Buffer) { final int start = getStart(); final int end = getEnd(); final byte[] bytes = new byte[end - start]; final Buffer currentBuffer = getBufferChunk().getBuffer(); final int pos = currentBuffer.position(); final int lim = currentBuffer.limit(); Buffers.setPositionLimit(currentBuffer, start, end); currentBuffer.get(bytes); Buffers.setPositionLimit(currentBuffer, pos, lim); setBytes(bytes); } } }; // Decoded Request URI private final DataChunk decodedRequestURIDC = DataChunk.newInstance(); private byte[] preallocatedDecodedURIBuffer; public void init(final Buffer input, final int start, final int end) { originalRequestURIDC.setBuffer(input, start, end); requestURIDC.setBuffer(input, start, end); } public void init(final byte[] input, final int start, final int end) { originalRequestURIDC.setBytes(input, start, end); requestURIDC.setBytes(input, start, end); } public void init(final String requestUri) { originalRequestURIDC.setString(requestUri); requestURIDC.setString(requestUri); } public final DataChunk getOriginalRequestURIBC() { return originalRequestURIDC; } public final DataChunk getRequestURIBC() { return requestURIDC; } public final DataChunk getDecodedRequestURIBC() throws CharConversionException { return getDecodedRequestURIBC(wasSlashAllowed, wasBackSlashAllowed, defaultURIEncoding); } public DataChunk getDecodedRequestURIBC( final boolean isSlashAllowed, final boolean isBackSlashAllowed) throws CharConversionException { return getDecodedRequestURIBC(isSlashAllowed, isBackSlashAllowed, defaultURIEncoding); } public DataChunk getDecodedRequestURIBC( final boolean isSlashAllowed, final boolean isBackSlashAllowed, final Charset charset) throws CharConversionException { if (isDecoded && isSlashAllowed == wasSlashAllowed && isBackSlashAllowed == wasBackSlashAllowed && charset == decodedURIEncoding) { return decodedRequestURIDC; } checkDecodedURICapacity(requestURIDC.getLength()); decodedRequestURIDC.setBytes(preallocatedDecodedURIBuffer); HttpRequestURIDecoder.decode( requestURIDC, decodedRequestURIDC, isSlashAllowed, isBackSlashAllowed, charset); isDecoded = true; wasSlashAllowed = isSlashAllowed; wasBackSlashAllowed = isBackSlashAllowed; decodedURIEncoding = charset; return decodedRequestURIDC; } public String getURI() { return getURI(null); } public String getURI(final Charset encoding) { return getRequestURIBC().toString(encoding); } public void setURI(final String uri) { getRequestURIBC().setString(uri); } public final String getDecodedURI() throws CharConversionException { return getDecodedURI(wasSlashAllowed, wasBackSlashAllowed); } public final String getDecodedURI(final boolean isSlashAllowed, final boolean isBackSlashAllowed) throws CharConversionException { return getDecodedURI(isSlashAllowed, isBackSlashAllowed, defaultURIEncoding); } public String getDecodedURI( final boolean isSlashAllowed, final boolean isBackSlashAllowed, Charset encoding) throws CharConversionException { getDecodedRequestURIBC(isSlashAllowed, isBackSlashAllowed, encoding); return decodedRequestURIDC.toString(); } public void setDecodedURI(String uri) { decodedRequestURIDC.setString(uri); isDecoded = true; } public boolean isDecoded() { return isDecoded; } public Charset getDefaultURIEncoding() { return defaultURIEncoding; } public void setDefaultURIEncoding(Charset defaultURIEncoding) { this.defaultURIEncoding = defaultURIEncoding; } public void recycle() { originalRequestURIDC.recycle(); decodedRequestURIDC.recycle(); requestURIDC.recycle(); isDecoded = false; wasSlashAllowed = true; wasBackSlashAllowed = true; decodedURIEncoding = null; defaultURIEncoding = UTF8_CHARSET; } private void checkDecodedURICapacity(final int size) { if (preallocatedDecodedURIBuffer == null || preallocatedDecodedURIBuffer.length < size) { // for static allocation it's better to wrap byte[] preallocatedDecodedURIBuffer = new byte[size]; } } }
public void setDecodedURI(String uri) { decodedRequestURIDC.setString(uri); isDecoded = true; }
public void init(final String requestUri) { originalRequestURIDC.setString(requestUri); requestURIDC.setString(requestUri); }