コード例 #1
0
 protected void fillFields(byte[] data, int offset) {
   field_1_rgf = LittleEndian.getShort(data, 0x0 + offset);
   field_2_unused = LittleEndian.getShort(data, 0x2 + offset);
   field_3_brcTop = new BorderCode(data, 0x4 + offset);
   field_4_brcLeft = new BorderCode(data, 0x8 + offset);
   field_5_brcBottom = new BorderCode(data, 0xc + offset);
   field_6_brcRight = new BorderCode(data, 0x10 + offset);
 }
コード例 #2
0
ファイル: SttbUtils.java プロジェクト: feiwei9696/POI-Android
  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;
  }
コード例 #3
0
  public void testWrite() {
    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet sheet = workbook.createSheet();
    CFRuleRecord rr = CFRuleRecord.create(sheet, ComparisonOperator.BETWEEN, "5", "10");

    PatternFormatting patternFormatting = new PatternFormatting();
    patternFormatting.setFillPattern(PatternFormatting.BRICKS);
    rr.setPatternFormatting(patternFormatting);

    byte[] data = rr.serialize();
    assertEquals(26, data.length);
    assertEquals(3, LittleEndian.getShort(data, 6));
    assertEquals(3, LittleEndian.getShort(data, 8));

    int flags = LittleEndian.getInt(data, 10);
    assertEquals("unused flags should be 111", 0x00380000, flags & 0x00380000);
    assertEquals(
        "undocumented flags should be 0000", 0, flags & 0x03C00000); // Otherwise Excel gets unhappy
    // check all remaining flag bits (some are not well understood yet)
    assertEquals(0x203FFFFF, flags);
  }
コード例 #4
0
  /** Get the date found in the byte array, as a java Data object */
  public static Date getDate(byte[] data, int offset) {
    Calendar cal = new GregorianCalendar();

    cal.set(Calendar.YEAR, LittleEndian.getShort(data, offset));
    cal.set(Calendar.MONTH, LittleEndian.getShort(data, offset + 2) - 1);
    // Not actually needed - can be found from day of month
    // cal.set(Calendar.DAY_OF_WEEK,  LittleEndian.getShort(data,offset+4)+1);
    cal.set(Calendar.DAY_OF_MONTH, LittleEndian.getShort(data, offset + 6));
    cal.set(Calendar.HOUR_OF_DAY, LittleEndian.getShort(data, offset + 8));
    cal.set(Calendar.MINUTE, LittleEndian.getShort(data, offset + 10));
    cal.set(Calendar.SECOND, LittleEndian.getShort(data, offset + 12));
    cal.set(Calendar.MILLISECOND, LittleEndian.getShort(data, offset + 14));

    return cal.getTime();
  }
コード例 #5
0
  private static int findText(byte[] tableStream, int complexOffset, ArrayList<WordTextPiece> text)
      throws IOException {
    // actual text
    int pos = complexOffset;
    int multiple = 2;
    // skips through the prms before we reach the piece table. These contain
    // data
    // for actual fast saved files
    while (tableStream[pos] == 1) {
      pos++;
      int skip = LittleEndian.getShort(tableStream, pos);
      pos += 2 + skip;
    }
    if (tableStream[pos] != 2) {
      throw new IOException("corrupted Word file");
    } else {
      // parse out the text pieces
      int pieceTableSize = LittleEndian.getInt(tableStream, ++pos);
      pos += 4;
      int pieces = (pieceTableSize - 4) / 12;
      for (int x = 0; x < pieces; x++) {
        int filePos = LittleEndian.getInt(tableStream, pos + ((pieces + 1) * 4) + (x * 8) + 2);
        boolean unicode = false;
        if ((filePos & 0x40000000) == 0) {
          unicode = true;
        } else {
          unicode = false;
          multiple = 1;
          filePos &= ~(0x40000000); // gives me FC in doc stream
          filePos /= 2;
        }
        int totLength =
            LittleEndian.getInt(tableStream, pos + (x + 1) * 4)
                - LittleEndian.getInt(tableStream, pos + (x * 4));

        WordTextPiece piece = new WordTextPiece(filePos, totLength, unicode);
        text.add(piece);
      }
    }
    return multiple;
  }
コード例 #6
0
ファイル: FIBFieldHandler.java プロジェクト: chiyiangel/UXIN
 public FIBFieldHandler(
     byte mainStream[],
     int startOffset,
     byte tableStream[],
     HashSet offsetList,
     boolean areKnown) {
   _unknownMap = new HashMap();
   int numFields = LittleEndian.getShort(mainStream, startOffset);
   int offset = startOffset + 2;
   _fields = new int[numFields * 2];
   for (int x = 0; x < numFields; x++) {
     int fieldOffset = x * 8 + offset;
     int dsOffset = LittleEndian.getInt(mainStream, fieldOffset);
     fieldOffset += 4;
     int dsSize = LittleEndian.getInt(mainStream, fieldOffset);
     if (offsetList.contains(Integer.valueOf(x)) ^ areKnown && dsSize > 0)
       if (dsOffset + dsSize > tableStream.length) {
         log.log(
             POILogger.WARN,
             (new StringBuilder())
                 .append("Unhandled data structure points to outside the buffer. offset = ")
                 .append(dsOffset)
                 .append(", length = ")
                 .append(dsSize)
                 .append(", buffer length = ")
                 .append(tableStream.length)
                 .toString());
       } else {
         UnhandledDataStructure unhandled =
             new UnhandledDataStructure(tableStream, dsOffset, dsSize);
         _unknownMap.put(Integer.valueOf(x), unhandled);
       }
     _fields[x * 2] = dsOffset;
     _fields[x * 2 + 1] = dsSize;
   }
 }
コード例 #7
0
ファイル: EscherRecord.java プロジェクト: aw1621107/hacks
 /**
  * Read the options field from header and return instance part of it.
  *
  * @param data the byte array to read from
  * @param offset the offset to start reading from
  * @return value of instance part of options field
  */
 protected static short readInstance(byte data[], int offset) {
   final short options = LittleEndian.getShort(data, offset);
   return fInstance.getShortValue(options);
 }
コード例 #8
0
ファイル: EscherRecord.java プロジェクト: aw1621107/hacks
 /**
  * Reads the 8 byte header information and populates the <code>options</code> and <code>recordId
  * </code> records.
  *
  * @param data the byte array to read from
  * @param offset the offset to start reading from
  * @return the number of bytes remaining in this record. This may include the children if this is
  *     a container.
  */
 protected int readHeader(byte[] data, int offset) {
   _options = LittleEndian.getShort(data, offset);
   _recordId = LittleEndian.getShort(data, offset + 2);
   int remainingBytes = LittleEndian.getInt(data, offset + 4);
   return remainingBytes;
 }
コード例 #9
0
 public DropCapSpecifier(byte[] buf, int offset) {
   this(LittleEndian.getShort(buf, offset));
 }
コード例 #10
0
  public String extractText(InputStream in) throws IOException {
    ArrayList<WordTextPiece> text = new ArrayList<WordTextPiece>();
    POIFSFileSystem fsys = new POIFSFileSystem(in);

    DocumentEntry headerProps = (DocumentEntry) fsys.getRoot().getEntry("WordDocument");
    DocumentInputStream din = fsys.createDocumentInputStream("WordDocument");
    byte[] header = new byte[headerProps.getSize()];

    din.read(header);
    din.close();
    // Prende le informazioni dall'header del documento
    int info = LittleEndian.getShort(header, 0xa);

    boolean useTable1 = (info & 0x200) != 0;

    // boolean useTable1 = true;

    // Prende informazioni dalla piece table
    int complexOffset = LittleEndian.getInt(header, 0x1a2);
    // int complexOffset = LittleEndian.getInt(header);

    String tableName = null;
    if (useTable1) {
      tableName = "1Table";
    } else {
      tableName = "0Table";
    }

    DocumentEntry table = (DocumentEntry) fsys.getRoot().getEntry(tableName);
    byte[] tableStream = new byte[table.getSize()];

    din = fsys.createDocumentInputStream(tableName);

    din.read(tableStream);
    din.close();

    din = null;
    fsys = null;
    table = null;
    headerProps = null;

    int multiple = findText(tableStream, complexOffset, text);

    StringBuffer sb = new StringBuffer();
    tableStream = null;

    for (int x = 0; x < text.size(); x++) {

      WordTextPiece nextPiece = (WordTextPiece) text.get(x);
      int start = nextPiece.getStart();
      int length = nextPiece.getLength();

      boolean unicode = nextPiece.usesUnicode();
      String toStr = null;
      if (unicode) {
        toStr = new String(header, start, length * multiple, "UTF-8");
      } else {
        toStr = new String(header, start, length, "big5");
      }
      sb.append(toStr).append(" ");
    }
    return sb.toString();
  }