/** Return the "name" of the timestamp. This can be used * to associate unique identifier with each timestamped object. * The name is a MessageBytes - i.e. a modifiable byte[] or char[]. */ public MessageBytes getName() { if( name==null ) name=MessageBytes.newInstance();//lazy return name; }
public void recycle() { creationTime = 0L; lastAccessedTime = 0L; maxInactiveInterval = -1; isNew = true; isValid = false; id=-1; if( name!=null) name.recycle(); }
@SuppressWarnings({"deprecation"}) public MessageBytes newInstance() { return new MessageBytes(); } }
/** * Character conversion of a US-ASCII MessageBytes. */ public static void convertASCII(MessageBytes mb) { // This is of course only meaningful for bytes if (mb.getType() != MessageBytes.T_BYTES) return; ByteChunk bc = mb.getByteChunk(); CharChunk cc = mb.getCharChunk(); int length = bc.getLength(); cc.allocate(length, -1); // Default encoding: fast conversion byte[] bbuf = bc.getBuffer(); char[] cbuf = cc.getBuffer(); int start = bc.getStart(); for (int i = 0; i < length; i++) { cbuf[i] = (char) (bbuf[i + start] & 0xff); } mb.setChars(cbuf, 0, length); } // END CR 6309511
/** Copy the src into this MessageBytes, allocating more space if * needed */ public void duplicate( MessageBytes src ) throws IOException { // START CR 6309514 // Discard previous state before duplicating recycle(); // END CR 6309514 switch( src.getType() ) { case MessageBytes.T_BYTES: type=T_BYTES; ByteChunk bc=src.getByteChunk(); byteC.allocate( 2 * bc.getLength(), -1 ); byteC.append( bc ); break; case MessageBytes.T_CHARS: type=T_CHARS; CharChunk cc=src.getCharChunk(); charC.allocate( 2 * cc.getLength(), -1 ); charC.append( cc ); break; case MessageBytes.T_STR: type=T_STR; String sc=src.getString(); this.setString( sc ); break; } }
/** * Normalize URI. * <p> * This method normalizes "\", "//", "/./" and "/../". This method will * return false when trying to go above the root, or if the URI contains * a null byte. * * @param uriMB URI to be normalized * @return <tt>true</tt> if normalization was successful, or <tt>false</tt> otherwise */ public static boolean normalize(MessageBytes uriMB) { int type = uriMB.getType(); if (type == MessageBytes.T_CHARS) { return normalizeChars(uriMB.getCharChunk()); } else { return normalizeBytes(uriMB.getByteChunk()); } }
/** * Map the specified URI relative to the context, * mutating the given mapping data. * * @param uri URI * @param mappingData This structure will contain the result of the mapping * operation */ public void map(MessageBytes uri, MappingData mappingData) throws Exception { uri.toChars(); CharChunk uricc = uri.getCharChunk(); uricc.setLimit(-1); internalMapWrapper(context, uricc, mappingData); }
public DispatchData() { uriMB = MessageBytes.newInstance(); CharChunk uriCC = uriMB.getCharChunk(); uriCC.setLimit(-1); mappingData = new MappingData(); } }
/** * Compares the message bytes to the specified String object. * @param s the String to compare * @return true if the comparison succeeded, false otherwise */ public boolean equals(String s) { if( s == null ) return false; if( ! caseSensitive ) return equalsIgnoreCase( s ); switch (type) { case T_STR: return strValue != null && strValue.equals(s); case T_CHARS: return charC.equals( s ); case T_BYTES: return byteC.equals( s ); default: return false; } }
/** * Normalize URI. * <p> * This method normalizes "\", "//", "/./" and "/../". This method will * return false when trying to go above the root, or if the URI contains * a null byte. * * @param uriMB URI to be normalized */ public static boolean normalize(MessageBytes uriMB) { int type = uriMB.getType(); if (type == MessageBytes.T_CHARS) { return normalizeChars(uriMB); } else { return normalizeBytes(uriMB); } }
/** * Character conversion of a US-ASCII MessageBytes. */ public static void convertASCII(MessageBytes mb) { // This is of course only meaningful for bytes if (mb.getType() != MessageBytes.T_BYTES) return; ByteChunk bc = mb.getByteChunk(); CharChunk cc = mb.getCharChunk(); int length = bc.getLength(); cc.allocate(length, -1); // Default encoding: fast conversion byte[] bbuf = bc.getBuffer(); char[] cbuf = cc.getBuffer(); int start = bc.getStart(); for (int i = 0; i < length; i++) { cbuf[i] = (char) (bbuf[i + start] & 0xff); } mb.setChars(cbuf, 0, length); } // END CR 6309511
/** Copy the src into this MessageBytes, allocating more space if * needed */ public void duplicate( MessageBytes src ) throws IOException { // START CR 6309514 // Discard previous state before duplicating recycle(); // END CR 6309514 switch( src.getType() ) { case MessageBytes.T_BYTES: type=T_BYTES; ByteChunk bc=src.getByteChunk(); byteC.allocate( 2 * bc.getLength(), -1 ); byteC.append( bc ); break; case MessageBytes.T_CHARS: type=T_CHARS; CharChunk cc=src.getCharChunk(); charC.allocate( 2 * cc.getLength(), -1 ); charC.append( cc ); break; case MessageBytes.T_STR: type=T_STR; String sc=src.getString(); this.setString( sc ); break; } }
/** * Normalize URI. * <p> * This method normalizes "\", "//", "/./" and "/../". This method will * return false when trying to go above the root, or if the URI contains * a null byte. * * @param uriMB URI to be normalized * @return <tt>true</tt> if normalization was successful, or <tt>false</tt> otherwise */ public static boolean normalize(MessageBytes uriMB) { int type = uriMB.getType(); if (type == MessageBytes.T_CHARS) { return normalizeChars(uriMB.getCharChunk()); } else { return normalizeBytes(uriMB.getByteChunk()); } }
/** * Map the specified URI relative to the context, * mutating the given mapping data. * * @param uri URI * @param mappingData This structure will contain the result of the mapping * operation */ public void map(MessageBytes uri, MappingData mappingData) throws Exception { uri.toChars(); CharChunk uricc = uri.getCharChunk(); uricc.setLimit(-1); internalMapWrapper(context, uricc, mappingData); }
private HttpServletMapping computeNamedDispatchHttpServletMapping(Context context, HttpServletRequest hcurrent) { HttpServletMapping result = null; Mapper mapper = context.getMapper(); if (null == mapper) { return null; } MessageBytes uriMB = MessageBytes.newInstance(); CharChunk cc = uriMB.getCharChunk(); MappingData mappingData = new MappingData(); String requestURI = hcurrent.getRequestURI(); if (null == requestURI) { return null; } try { cc.append(requestURI, 0, requestURI.length()); mapper.map(uriMB, mappingData); } catch (Exception ex) { return null; } result = new MappingImpl(mappingData); return result; }
/** * Compares the message bytes to the specified String object. * @param s the String to compare * @return true if the comparison succeeded, false otherwise */ public boolean equals(String s) { if( s == null ) return false; if( ! caseSensitive ) return equalsIgnoreCase( s ); switch (type) { case T_STR: return strValue != null && strValue.equals(s); case T_CHARS: return charC.equals( s ); case T_BYTES: return byteC.equals( s ); default: return false; } }
/** * Character conversion of a US-ASCII MessageBytes. */ public static void convertASCII(MessageBytes mb) { // This is of course only meaningful for bytes if (mb.getType() != MessageBytes.T_BYTES) return; ByteChunk bc = mb.getByteChunk(); CharChunk cc = mb.getCharChunk(); int length = bc.getLength(); cc.allocate(length, -1); // Default encoding: fast conversion byte[] bbuf = bc.getBuffer(); char[] cbuf = cc.getBuffer(); int start = bc.getStart(); for (int i = 0; i < length; i++) { cbuf[i] = (char) (bbuf[i + start] & 0xff); } mb.setChars(cbuf, 0, length); } // END CR 6309511
/** Copy the src into this MessageBytes, allocating more space if * needed */ public void duplicate( MessageBytes src ) throws IOException { // START CR 6309514 // Discard previous state before duplicating recycle(); // END CR 6309514 switch( src.getType() ) { case MessageBytes.T_BYTES: type=T_BYTES; ByteChunk bc=src.getByteChunk(); byteC.allocate( 2 * bc.getLength(), -1 ); byteC.append( bc ); break; case MessageBytes.T_CHARS: type=T_CHARS; CharChunk cc=src.getCharChunk(); charC.allocate( 2 * cc.getLength(), -1 ); charC.append( cc ); break; case MessageBytes.T_STR: type=T_STR; String sc=src.getString(); this.setString( sc ); break; } }