/** * Given a byte array of 16-bit unicode characters in little endian * format (most important byte last), return a Java String representation * of it. * <p> * { 0x16, 0x00 } -0x16 * * @param string the byte array to be converted * @return the converted string, never <code>null</code> */ public static String getFromUnicodeLE(byte[] string) { if (string.length == 0) { return ""; } return getFromUnicodeLE(string, 0, string.length / 2); }
public LbsDropData(LittleEndianInput in){ _wStyle = in.readUShort(); _cLine = in.readUShort(); _dxMin = in.readUShort(); _str = StringUtil.readUnicodeString(in); if(StringUtil.getEncodedSize(_str) % 2 != 0){ _unused = in.readByte(); } }
/** * OutputStream <tt>out</tt> will get: * <ol> * <li>byte is16BitFlag</li> * <li>byte[]/char[] characterData</li> * </ol> * For this encoding, the is16BitFlag is always present even if nChars==0. * <br> * This method should be used when the nChars field is <em>not</em> stored * as a ushort immediately before the is16BitFlag. Otherwise, {@link * #writeUnicodeString(LittleEndianOutput, String)} can be used. */ public static void writeUnicodeStringFlagAndData(LittleEndianOutput out, String value) { boolean is16Bit = hasMultibyte(value); out.writeByte(is16Bit ? 0x01 : 0x00); if (is16Bit) { putUnicodeLE(value, out); } else { putCompressedUnicode(value, out); } }
/** * InputStream <tt>in</tt> is expected to contain: * <ol> * <li>byte is16BitFlag</li> * <li>byte[]/char[] characterData</li> * </ol> * For this encoding, the is16BitFlag is always present even if nChars==0. * <br> * This method should be used when the nChars field is <em>not</em> stored * as a ushort immediately before the is16BitFlag. Otherwise, {@link * #readUnicodeString(LittleEndianInput)} can be used. */ public static String readUnicodeString(LittleEndianInput in, int nChars) { byte is16Bit = in.readByte(); if ((is16Bit & 0x01) == 0) { return readCompressedUnicode(in, nChars); } return readUnicodeLE(in, nChars); }
public void write(LittleEndianOutput out) { out.writeByte(sid + getPtgClass()); out.writeByte(field_3_string.length()); // Note - nChars is 8-bit out.writeByte(_is16bitUnicode ? 0x01 : 0x00); if (_is16bitUnicode) { StringUtil.putUnicodeLE(field_3_string, out); } else { StringUtil.putCompressedUnicode(field_3_string, out); } }
label = StringUtil.getFromCompressedUnicode(data, ofs, len - 1); ofs += len; fileName = StringUtil.getFromCompressedUnicode(data, ofs, len - 1); ofs += len; command = StringUtil.getFromCompressedUnicode(data, ofs, len - 1); ofs += len;
/** * Constructs a single new string attribute from the id, type, * and the contents of the stream */ protected TNEFStringAttribute(int id, int type, InputStream inp) throws IOException { super(id, type, inp); String tmpData = null; byte[] data = getData(); if(getType() == TNEFProperty.TYPE_TEXT) { tmpData = StringUtil.getFromUnicodeLE(data); } else { tmpData = StringUtil.getFromCompressedUnicode( data, 0, data.length ); } // Strip off the null terminator if present if(tmpData.endsWith("\0")) { tmpData = tmpData.substring(0, tmpData.length()-1); } this.data = tmpData; }
private static void serializeUnicodeString(UnicodeString us, LittleEndianOutput out) { StringUtil.writeUnicodeString(out, us.getString()); } private static int getUnicodeStringSize(UnicodeString us) {
/** * Name of the original comment author * * @param author the name of the original author of the comment */ public void setAuthor(String author) { field_6_author = author; field_5_hasMultibyte = StringUtil.hasMultibyte(author); }
public int getDataSize() { int size = 6; size += StringUtil.getEncodedSize(_str); if(_unused != null) { size++; } return size; }
public FeatProtection(RecordInputStream in) { fSD = in.readInt(); passwordVerifier = in.readInt(); title = StringUtil.readUnicodeString(in); securityDescriptor = in.readRemainder(); }
@Override protected void serialize(LittleEndianOutput out) { out.writeShort(rt); out.writeShort(grbitFrt); out.write(unused); out.writeInt(cts); out.writeShort(rgchDefListStyle.length()); out.writeShort(rgchDefPivotStyle.length()); StringUtil.putUnicodeLE(rgchDefListStyle, out); StringUtil.putUnicodeLE(rgchDefPivotStyle, out); }
public static String readUnicodeLPP4(LittleEndianInput is) { int length = is.readInt(); if (length%2 != 0) { throw new EncryptedDocumentException( "UNICODE-LP-P4 structure is a multiple of 4 bytes. " + "If Padding is present, it MUST be exactly 2 bytes long"); } String result = StringUtil.readUnicodeLE(is, length/2); if (length%4==2) { // Padding (variable): A set of bytes that MUST be of the correct size such that the size of the // UNICODE-LP-P4 structure is a multiple of 4 bytes. If Padding is present, it MUST be exactly // 2 bytes long, and each byte MUST be 0x00. is.readShort(); } return result; }
public void serialize(LittleEndianOutput out) { // TODO - junit out.writeShort(getReadOnly()); out.writeShort(getPassword()); out.writeShort(field_3_username_value.length()); if(field_3_username_value.length() > 0) { out.writeByte(field_3_username_unicode_options); StringUtil.putCompressedUnicode(getUsername(), out); } }
/** Create a StringPtg from a stream */ public StringPtg(LittleEndianInput in) { int nChars = in.readUByte(); // Note - nChars is 8-bit _is16bitUnicode = (in.readByte() & 0x01) != 0; if (_is16bitUnicode) { field_3_string = StringUtil.readUnicodeLE(in, nChars); } else { field_3_string = StringUtil.readCompressedUnicode(in, nChars); } }
public void serialize(LittleEndianOutput out) { out.writeShort(field_1_id); out.writeByte(field_4_text.length()); if (is16bit) { // Excel (2007) seems to choose 16bit regardless of whether it is needed out.writeByte(0x01); StringUtil.putUnicodeLE(field_4_text, out); } else { // Excel can read this OK out.writeByte(0x00); StringUtil.putCompressedUnicode(field_4_text, out); } }
private String read2004String(InputStream stream) throws IOException, TikaException { int stringLen = EndianUtils.readUShortLE(stream); byte[] stringData = new byte[stringLen]; IOUtils.readFully(stream, stringData); // Often but not always null terminated if (stringData[stringLen-1] == 0) { stringLen--; } String value = StringUtil.getFromCompressedUnicode(stringData, 0, stringLen); return value; }
/** * Constructs a single new string attribute from the id, type, * and the contents of the stream */ protected TNEFStringAttribute(int id, int type, InputStream inp) throws IOException { super(id, type, inp); String tmpData = null; byte[] data = getData(); if(getType() == TNEFProperty.TYPE_TEXT) { tmpData = StringUtil.getFromUnicodeLE(data); } else { tmpData = StringUtil.getFromCompressedUnicode( data, 0, data.length ); } // Strip off the null terminator if present if(tmpData.endsWith("\0")) { tmpData = tmpData.substring(0, tmpData.length()-1); } this.data = tmpData; }
public void serialize(LittleEndianOutput out) { out.writeShort(field_1_number_of_sheets); if(isExternalReferences()) { StringUtil.writeUnicodeString(out, field_2_encoded_url); for(int i=0; i<field_3_sheet_names.length; i++) { StringUtil.writeUnicodeString(out, field_3_sheet_names[i]); } } else { int field2val = _isAddInFunctions ? TAG_ADD_IN_FUNCTIONS : TAG_INTERNAL_REFERENCES; out.writeShort(field2val); } }
public FormatRecord(int indexCode, String fs) { field_1_index_code = indexCode; field_4_formatstring = fs; field_3_hasMultibyte = StringUtil.hasMultibyte(fs); }