Пример #1
0
  static Sttb read(int cDataLength, byte[] buffer, int startOffset) {
    short ffff = LittleEndian.getShort(buffer, startOffset);
    int offset = startOffset + 2;

    if (ffff != (short) 0xffff) {
      // Non-extended character Pascal strings
      throw new UnsupportedOperationException(
          "Non-extended character Pascal strings are not supported right now. "
              + "Please, contact POI developers for update.");
    }
    // strings are extended character strings

    int cData =
        cDataLength == 2
            ? LittleEndian.getUShort(buffer, offset)
            : LittleEndian.getInt(buffer, offset);
    offset += cDataLength;

    Sttb sttb = new Sttb();
    sttb.cDataLength = cDataLength;
    sttb.cbExtra = LittleEndian.getUShort(buffer, offset);
    offset += 2;

    sttb.data = new String[cData];
    sttb.extraData = new byte[cData][];

    for (int i = 0; i < cData; i++) {
      int cchData = LittleEndian.getShort(buffer, offset);
      offset += 2;

      if (cchData < 0) continue;

      sttb.data[i] = StringUtil.getFromUnicodeLE(buffer, offset, cchData);
      offset += cchData * 2;

      sttb.extraData[i] = LittleEndian.getByteArray(buffer, offset, sttb.cbExtra);
      offset += sttb.cbExtra;
    }

    return sttb;
  }
  public MAPIStringAttribute(MAPIProperty property, int type, byte[] data) {
    super(property, type, data);

    String tmpData = null;
    if (type == Types.ASCII_STRING) {
      try {
        tmpData = new String(data, CODEPAGE);
      } catch (UnsupportedEncodingException e) {
        throw new RuntimeException("JVM Broken - core encoding " + CODEPAGE + " missing");
      }
    } else if (type == Types.UNICODE_STRING) {
      tmpData = StringUtil.getFromUnicodeLE(data);
    } else {
      throw new IllegalArgumentException("Not a string type " + type);
    }

    // Strip off the null terminator if present
    if (tmpData.endsWith("\0")) {
      tmpData = tmpData.substring(0, tmpData.length() - 1);
    }
    this.data = tmpData;
  }