@Override
 public void read(DataInput stream) throws IOException {
   OffsetTrackingInputStream inputStream = (OffsetTrackingInputStream) stream;
   long startOffset = inputStream.getOffset();
   super.read(stream);
   long length = getValue("wLength");
   int i = 0;
   while (inputStream.getOffset() < startOffset + length) {
     StringTable stringTableReader = new StringTable("StringTable" + (i++));
     stringTableReader.read(inputStream);
     addMember(stringTableReader);
   }
 }
Exemple #2
0
  /**
   * Writes and compresses a single byte to the underlying output stream.
   *
   * @param b byte to write
   * @throws IOException if anything goes wrong
   */
  @Override
  public void write(int b) throws IOException {
    if (prefixCode == -1) {
      prefixCode = b;
    } else {
      int newPrefixCode = table.codeValue(prefixCode, (byte) b);
      if (newPrefixCode != -1) {
        prefixCode = newPrefixCode;
      } else {
        writer.write(prefixCode);
        boolean added = table.add(prefixCode, (byte) b);

        if (added && codeWidthNeedsToBeIncreased()) {
          writer.increaseCodeWidth();
          codeWidth++;
        }

        prefixCode = b;
      }
    }
  }
  @Test
  public void simpleImport() throws ParseException {
    String data = "columnA,columnB\nvalue1A,value1B\nvalue2A,value2B";

    StringTable result = underTest.parse(data);

    assertEquals(2, result.getColumnCount());
    assertEquals(2, result.getRowCount());

    assertEquals("columnA", result.getColumnName(0));
    assertEquals("columnB", result.getColumnName(1));

    assertEquals("value1A", result.getValue(0, 0));
    assertEquals("value1B", result.getValue(0, 1));
    assertEquals("value2A", result.getValue(1, 0));
    assertEquals("value2B", result.getValue(1, 1));
  }
Exemple #4
0
 private boolean codeWidthNeedsToBeIncreased() {
   int maxCodeForCurrentWidth = (int) Math.pow(2, codeWidth);
   return (codeWidth < maxCodeWidth) && (maxCodeForCurrentWidth + 1) == table.nextCode();
 }