📄 parameters.java
字号:
System.arraycopy(twoValue, 0, combinedValue, 0, twoValue.length); } else { combinedValue = new String[oneValue.length + twoValue.length]; System.arraycopy(oneValue, 0, combinedValue, 0, oneValue.length); System.arraycopy(twoValue, 0, combinedValue, oneValue.length, twoValue.length); } one.put(name, combinedValue); } } } // incredibly inefficient data representation for parameters, // until we test the new one private void addParam( String key, String value ) { if( key==null ) return; String values[]; if (paramHashStringArray.containsKey(key)) { String oldValues[] = (String[])paramHashStringArray. get(key); values = new String[oldValues.length + 1]; for (int i = 0; i < oldValues.length; i++) { values[i] = oldValues[i]; } values[oldValues.length] = value; } else { values = new String[1]; values[0] = value; } paramHashStringArray.put(key, values); } public void setURLDecoder( UDecoder u ) { urlDec=u; } // -------------------- Parameter parsing -------------------- // This code is not used right now - it's the optimized version // of the above. // we are called from a single thread - we can do it the hard way // if needed ByteChunk tmpName=new ByteChunk(); ByteChunk tmpValue=new ByteChunk(); CharChunk tmpNameC=new CharChunk(1024); CharChunk tmpValueC=new CharChunk(1024); public void processParameters( byte bytes[], int start, int len ) { int end=start+len; int pos=start; if( debug>0 ) log( "Bytes: " + new String( bytes, start, len )); do { boolean noEq=false; int valStart=-1; int valEnd=-1; int nameStart=pos; int nameEnd=ByteChunk.indexOf(bytes, nameStart, end, '=' ); // Workaround for a&b&c encoding int nameEnd2=ByteChunk.indexOf(bytes, nameStart, end, '&' ); if( (nameEnd2!=-1 ) && ( nameEnd==-1 || nameEnd > nameEnd2) ) { nameEnd=nameEnd2; noEq=true; valStart=nameEnd; valEnd=nameEnd; if( debug>0) log("no equal " + nameStart + " " + nameEnd + " " + new String(bytes, nameStart, nameEnd-nameStart) ); } if( nameEnd== -1 ) nameEnd=end; if( ! noEq ) { valStart= (nameEnd < end) ? nameEnd+1 : end; valEnd=ByteChunk.indexOf(bytes, valStart, end, '&'); if( valEnd== -1 ) valEnd = (valStart < end) ? end : valStart; } pos=valEnd+1; if( nameEnd<=nameStart ) { continue; // invalid chunk - it's better to ignore // XXX log it ? } tmpName.setBytes( bytes, nameStart, nameEnd-nameStart ); tmpValue.setBytes( bytes, valStart, valEnd-valStart ); tmpName.setEncoding( encoding ); tmpValue.setEncoding( encoding ); try { if( debug > 0 ) log( "Found " + tmpName + "= " + tmpValue); if( urlDec==null ) { urlDec=new UDecoder(); } urlDec.convert( tmpName ); urlDec.convert( tmpValue ); if( debug > 0 ) log( "After url decoding " + tmpName + "= " + tmpValue); addParam( tmpName.toString(), tmpValue.toString() ); } catch( IOException ex ) { ex.printStackTrace(); } tmpName.recycle(); tmpValue.recycle(); } while( pos<end ); } public void processParameters( char chars[], int start, int len ) { int end=start+len; int pos=start; if( debug>0 ) log( "Chars: " + new String( chars, start, len )); do { boolean noEq=false; int nameStart=pos; int valStart=-1; int valEnd=-1; int nameEnd=CharChunk.indexOf(chars, nameStart, end, '=' ); int nameEnd2=CharChunk.indexOf(chars, nameStart, end, '&' ); if( (nameEnd2!=-1 ) && ( nameEnd==-1 || nameEnd > nameEnd2) ) { nameEnd=nameEnd2; noEq=true; valStart=nameEnd; valEnd=nameEnd; if( debug>0) log("no equal " + nameStart + " " + nameEnd + " " + new String(chars, nameStart, nameEnd-nameStart) ); } if( nameEnd== -1 ) nameEnd=end; if( ! noEq ) { valStart= (nameEnd < end) ? nameEnd+1 : end; valEnd=CharChunk.indexOf(chars, valStart, end, '&'); if( valEnd== -1 ) valEnd = (valStart < end) ? end : valStart; } pos=valEnd+1; if( nameEnd<=nameStart ) { continue; // invalid chunk - no name, it's better to ignore // XXX log it ? } try { tmpNameC.append( chars, nameStart, nameEnd-nameStart ); tmpValueC.append( chars, valStart, valEnd-valStart ); if( debug > 0 ) log( tmpNameC + "= " + tmpValueC); if( urlDec==null ) { urlDec=new UDecoder(); } urlDec.convert( tmpNameC ); urlDec.convert( tmpValueC ); if( debug > 0 ) log( tmpNameC + "= " + tmpValueC); addParam( tmpNameC.toString(), tmpValueC.toString() ); } catch( IOException ex ) { ex.printStackTrace(); } tmpNameC.recycle(); tmpValueC.recycle(); } while( pos<end ); } public void processParameters( MessageBytes data ) { if( data==null || data.isNull() || data.getLength() <= 0 ) return; if( data.getType() == MessageBytes.T_BYTES ) { ByteChunk bc=data.getByteChunk(); processParameters( bc.getBytes(), bc.getOffset(), bc.getLength()); } else { if (data.getType()!= MessageBytes.T_CHARS ) data.toChars(); CharChunk cc=data.getCharChunk(); processParameters( cc.getChars(), cc.getOffset(), cc.getLength()); } } /** Debug purpose */ public String paramsAsString() { StringBuffer sb=new StringBuffer(); Enumeration en= paramHashStringArray.keys(); while( en.hasMoreElements() ) { String k=(String)en.nextElement(); sb.append( k ).append("="); String v[]=(String[])paramHashStringArray.get( k ); for( int i=0; i<v.length; i++ ) sb.append( v[i] ).append(","); sb.append("\n"); } return sb.toString(); } private static int debug=0; private void log(String s ) { System.out.println("Parameters: " + s ); } // -------------------- Old code, needs rewrite -------------------- /** Used by RequestDispatcher */ public void processParameters( String str ) { int end=str.length(); int pos=0; if( debug > 0) log("String: " + str ); do { boolean noEq=false; int valStart=-1; int valEnd=-1; int nameStart=pos; int nameEnd=str.indexOf('=', nameStart ); int nameEnd2=str.indexOf('&', nameStart ); if( nameEnd2== -1 ) nameEnd2=end; if( (nameEnd2!=-1 ) && ( nameEnd==-1 || nameEnd > nameEnd2) ) { nameEnd=nameEnd2; noEq=true; valStart=nameEnd; valEnd=nameEnd; if( debug>0) log("no equal " + nameStart + " " + nameEnd + " " + str.substring(nameStart, nameEnd) ); } if( nameEnd== -1 ) nameEnd=end; if( ! noEq ) { valStart=nameEnd+1; valEnd=str.indexOf('&', valStart); if( valEnd== -1 ) valEnd = (valStart < end) ? end : valStart; } pos=valEnd+1; if( nameEnd<=nameStart ) { continue; } if( debug>0) log( "XXX " + nameStart + " " + nameEnd + " " + valStart + " " + valEnd ); try { tmpNameC.append(str, nameStart, nameEnd-nameStart ); tmpValueC.append(str, valStart, valEnd-valStart ); if( debug > 0 ) log( tmpNameC + "= " + tmpValueC); if( urlDec==null ) { urlDec=new UDecoder(); } urlDec.convert( tmpNameC ); urlDec.convert( tmpValueC ); if( debug > 0 ) log( tmpNameC + "= " + tmpValueC); addParam( tmpNameC.toString(), tmpValueC.toString() ); } catch( IOException ex ) { ex.printStackTrace(); } tmpNameC.recycle(); tmpValueC.recycle(); } while( pos<end ); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -