protected int type;
protected String namePrefix;
- protected Chunk(String entryName) {
- int splitAt = entryName.lastIndexOf('_');
- if(splitAt == -1 || splitAt > (entryName.length()-8)) {
- throw new IllegalArgumentException("Invalid chunk name " + entryName);
- }
-
- namePrefix = entryName.substring(0, splitAt+1);
- String ids = entryName.substring(splitAt+1);
- chunkId = Integer.parseInt(ids.substring(0, 4), 16);
- type = Integer.parseInt(ids.substring(4, 8), 16);
- }
+ protected Chunk(String namePrefix, int chunkId, int type) {
+ this.namePrefix = namePrefix;
+ this.chunkId = chunkId;
+ this.type = type;
+ }
protected Chunk(int chunkId, int type) {
- namePrefix = DEFAULT_NAME_PREFIX;
- this.chunkId = chunkId;
- this.type = type;
+ this(DEFAULT_NAME_PREFIX, chunkId, type);
}
/**
* Creates a chunk, and gives it to its parent group
*/
protected static void process(DocumentNode entry, ChunkGroup grouping) {
- if(entry.getName().length() < 9) {
+ String entryName = entry.getName();
+
+ if(entryName.length() < 9) {
// Name in the wrong format
return;
}
- if(entry.getName().indexOf('_') == -1) {
+ if(entryName.indexOf('_') == -1) {
// Name in the wrong format
return;
}
- // See if we can get a type for it
- String idType = entry.getName().substring(entry.getName().length()-8);
- String idS = idType.substring(0, 4);
- String typeS = idType.substring(4);
+ // Split it into its parts
+ int splitAt = entryName.lastIndexOf('_');
+ if(splitAt == -1 || splitAt > (entryName.length()-8)) {
+ throw new IllegalArgumentException("Invalid chunk name " + entryName);
+ }
+
+ // Now try to turn it into id + type
+ String namePrefix = entryName.substring(0, splitAt+1);
+ String ids = entryName.substring(splitAt+1);
try {
- int id = Integer.parseInt(idS, 16);
- int type = Integer.parseInt(typeS, 16);
+ int chunkId = Integer.parseInt(ids.substring(0, 4), 16);
+ int type = Integer.parseInt(ids.substring(4, 8), 16);
+
Chunk chunk = null;
// Special cases based on the ID
- switch(id) {
+ switch(chunkId) {
case Chunks.SUBMISSION_ID_DATE:
- chunk = new MessageSubmissionChunk(entry.getName());
+ chunk = new MessageSubmissionChunk(namePrefix, chunkId, type);
break;
default:
// Nothing special about this ID
// So, do the usual thing which is by type
switch(type) {
case Types.BINARY:
- chunk = new ByteChunk(entry.getName());
+ chunk = new ByteChunk(namePrefix, chunkId, type);
break;
case Types.ASCII_STRING:
case Types.UNICODE_STRING:
- chunk = new StringChunk(entry.getName());
+ chunk = new StringChunk(namePrefix, chunkId, type);
break;
}
}
assertEquals(0x0200, chunk.getChunkId());
assertEquals(0x001E, chunk.getType());
- chunk = new StringChunk("__substg1.0_0200001E");
+ chunk = new StringChunk("__substg1.0_", 0x0200, 0x001E);
assertEquals("__substg1.0_0200001E", chunk.getEntryName());
assertEquals(0x0200, chunk.getChunkId());
assertEquals(0x001E, chunk.getType());