break;
case LITTLE_ENDIAN:
codecStrategy = new LittleEndianCodec(hexString);
break;
default:
throw new MTPException("Invalid endianness specifier");
}
try {
// Read 'string type_id' field
String typeID = codecStrategy.readString();
if(!typeID.equalsIgnoreCase(typeName))
throw new MTPException("Invalid type ID" + typeID);
}
catch (Exception e) { // all exceptions are converted into MTPException
throw new MTPException("Invalid type ID");
}
// Read 'sequence<TaggedProfile> profiles' field
// Read sequence length
int seqLen = codecStrategy.readLong();
for(int i = 0; i < seqLen; i++) {
// Read 'ProfileId tag' field
int tag = codecStrategy.readLong();
byte[] profile = codecStrategy.readOctetSequence();
if(tag == TAG_INTERNET_IOP) {
// Process IIOP profile
CDRCodec profileBodyCodec;
switch(profile[0]) {
case BIG_ENDIAN:
profileBodyCodec = new BigEndianCodec(profile);
break;
case LITTLE_ENDIAN:
profileBodyCodec = new LittleEndianCodec(profile);
break;
default:
throw new MTPException("Invalid endianness specifier");
}
// Read IIOP version
byte versionMajor = profileBodyCodec.readOctet();
byte versionMinor = profileBodyCodec.readOctet();
if(versionMajor != 1)
throw new MTPException("IIOP version not supported");
try {
// Read 'string host' field
host = profileBodyCodec.readString();
}
catch (Exception e) {
throw new MTPException("Invalid host string");
}
// Read 'unsigned short port' field
port = profileBodyCodec.readShort();
// Read 'sequence<octet> object_key' field and convert it
// into a String object
byte[] keyBuffer = profileBodyCodec.readOctetSequence();
ByteArrayOutputStream buf = new ByteArrayOutputStream();
// Escape every forbidden character, as for RFC 2396 (URI: Generic Syntax)
for(int ii = 0; ii < keyBuffer.length; ii++) {
byte b = keyBuffer[ii];
if(isUnreservedURIChar(b)) {
// Write the character 'as is'
buf.write(b);
}
else {
// Escape it using '%'
buf.write(ASCII_PERCENT);
buf.write(HEX[(b & 0xF0) >> 4]); // High nibble
buf.write(HEX[b & 0x0F]); // Low nibble
}
}
objectKey = buf.toString("US-ASCII");
codecStrategy = null;
}
}
}
catch (Exception e) { // all exceptions are converted into MTPException
throw new MTPException(e.getMessage());
}
}