switch (tempByte) {
case 'd' :
//create a new dictionary object
Map tempMap = new LightHashMap();
try{
//get the key
while (true) {
dbis.mark(Integer.MAX_VALUE);
tempByte = dbis.read();
if(tempByte == 'e' || tempByte == -1)
break; // end of map
dbis.reset();
// decode key strings manually so we can reuse the bytebuffer
int keyLength = (int)getPositiveNumberFromStream(dbis, ':');
if ( keyLength > MAX_MAP_KEY_SIZE ){
byte[] remaining = new byte[128];
getByteArrayFromStream(dbis, 128, remaining);
String msg = "dictionary key is too large, max=" + MAX_MAP_KEY_SIZE + ": value=" + new String(remaining);
System.err.println( msg );
throw( new IOException( msg ));
}
if(keyLength < keyBytesBuffer.capacity())
{
keyBytesBuffer.position(0).limit(keyLength);
keyCharsBuffer.position(0).limit(keyLength);
} else {
keyBytesBuffer = ByteBuffer.allocate(keyLength);
keyCharsBuffer = CharBuffer.allocate(keyLength);
}
getByteArrayFromStream(dbis, keyLength, keyBytesBuffer.array());
keyDecoder.reset();
keyDecoder.decode(keyBytesBuffer,keyCharsBuffer,true);
keyDecoder.flush(keyCharsBuffer);
String key = new String(keyCharsBuffer.array(),0,keyCharsBuffer.limit());
// keys often repeat a lot - intern to save space
if (internKeys)
key = StringInterner.intern( key );
//decode value
Object value = decodeInputStream(dbis,nesting+1,internKeys);
// value interning is too CPU-intensive, let's skip that for now
/*if(value instanceof byte[] && ((byte[])value).length < 17)
value = StringInterner.internBytes((byte[])value);*/
if ( TRACE ){
System.out.println( key + "->" + value + ";" );
}
// recover from some borked encodings that I have seen whereby the value has
// not been encoded. This results in, for example,
// 18:azureus_propertiesd0:e
// we only get null back here if decoding has hit an 'e' or end-of-file
// that is, there is no valid way for us to get a null 'value' here
if ( value == null ){
System.err.println( "Invalid encoding - value not serialsied for '" + key + "' - ignoring" );
break;
}
if ( tempMap.put( key, value) != null ){
Debug.out( "BDecoder: key '" + key + "' already exists!" );
}
}