/**
  * Reads a string
  *
  * @return String String
  */
 @Override
 public String readString(Type target) {
   int len = readAMF3Integer();
   log.debug("readString - length: {}", len);
   // get the length of the string (0x03 = 1, 0x05 = 2, 0x07 = 3 etc..)
   // 0x01 is special and it means "empty"
   if (len == 1) {
     // Empty string
     return "";
   }
   if ((len & 1) == 0) {
     // if the refs are empty an IndexOutOfBoundsEx will be thrown
     if (refStorage.stringReferences.isEmpty()) {
       log.debug("String reference list is empty");
     }
     // Reference
     return refStorage.stringReferences.get(len >> 1);
   }
   len >>= 1;
   log.debug("readString - new length: {}", len);
   int limit = buf.limit();
   log.debug("readString - limit: {}", limit);
   final ByteBuffer strBuf = buf.buf();
   strBuf.limit(strBuf.position() + len);
   final String string = AMF.CHARSET.decode(strBuf).toString();
   log.debug("String: {}", string);
   buf.limit(limit); // reset the limit
   refStorage.stringReferences.add(string);
   return string;
 }
 /** {@inheritDoc} */
 public Document readXML(Type target) {
   int len = readAMF3Integer();
   if (len == 1) {
     // Empty string, should not happen
     return null;
   }
   if ((len & 1) == 0) {
     // Reference
     return (Document) getReference(len >> 1);
   }
   len >>= 1;
   int limit = buf.limit();
   final ByteBuffer strBuf = buf.buf();
   strBuf.limit(strBuf.position() + len);
   final String xmlString = AMF.CHARSET.decode(strBuf).toString();
   buf.limit(limit); // Reset the limit
   Document doc = null;
   try {
     doc = XMLUtils.stringToDoc(xmlString);
   } catch (IOException ioex) {
     log.error("IOException converting xml to dom", ioex);
   }
   storeReference(doc);
   return doc;
 }
Exemplo n.º 3
0
 /** {@inheritDoc} */
 public void writeUTF(String value) {
   // fix from issue #97
   try {
     byte[] strBuf = value.getBytes(AMF.CHARSET.name());
     buffer.putShort((short) strBuf.length);
     buffer.put(strBuf);
   } catch (UnsupportedEncodingException e) {
     e.printStackTrace();
   }
 }
 /**
  * Reads a string of a set length. This does not use the string reference table.
  *
  * @param length the length of the string
  * @return String
  */
 public String readString(int length) {
   log.debug("readString - length: {}", length);
   int limit = buf.limit();
   final ByteBuffer strBuf = buf.buf();
   strBuf.limit(strBuf.position() + length);
   final String string = AMF.CHARSET.decode(strBuf).toString();
   log.debug("String: {}", string);
   buf.limit(limit);
   // check for null termination
   byte b = buf.get();
   if (b != 0) {
     buf.position(buf.position() - 1);
   }
   return string;
 }
Exemplo n.º 5
0
 /** {@inheritDoc} */
 public void writeUTFBytes(String value) {
   final java.nio.ByteBuffer strBuf = AMF.CHARSET.encode(value);
   buffer.put(strBuf);
 }