Package ivory.core.compression

Examples of ivory.core.compression.BitOutputStream


   * @param out where to write the serialized representation
   */
  @Override
  public void write(DataOutput out) throws IOException {
    ByteArrayOutputStream b = new ByteArrayOutputStream();
    BitOutputStream t = new BitOutputStream(b);
    for (int i = 0; i < tf; i++) {
      if (i == 0) {
        t.writeGamma(positions[0]);
      } else {
        int pgap = positions[i] - positions[i - 1];
        if (positions[i] <= 0 || pgap == 0) {
          throw new RuntimeException("Error: invalid term positions " + toString());
        }

        t.writeGamma(pgap);
      }
    }

    int bitOffset = t.getBitOffset();
    int byteOffset = (int) t.getByteOffset();
    t.padAndFlush();
    t.close();

    byte[] bytes = b.toByteArray();
    out.writeInt(bytes.length);
    out.writeShort(tf);
    out.writeInt(byteOffset * 8 + bitOffset);
View Full Code Here


    // is done as part of the deserialization process... if this is the case, then run through a
    // mock encoding to compute the encoded size.
    if (totalBits == 0) {
      try {
        ByteArrayOutputStream b = new ByteArrayOutputStream();
        BitOutputStream t = new BitOutputStream(b);
        for (int i = 0; i < tf; i++) {
          if (i == 0) {
            t.writeGamma(positions[0]);
          } else {
            int pgap = positions[i] - positions[i - 1];
            if (positions[i] <= 0 || pgap == 0) {
              throw new RuntimeException("Error: invalid term positions " + toString());
            }

            t.writeGamma(pgap);
          }
        }

        int bitOffset = t.getBitOffset();
        int byteOffset = (int) t.getByteOffset();
        t.padAndFlush();
        t.close();

        totalBits = byteOffset * 8 + bitOffset;
      } catch (Exception e) {
        e.printStackTrace();
      }
View Full Code Here

    this.cf = 0;
    this.prevDocno = -1;

    try {
      bytesOut = new ByteArrayOutputStream();
      bitOut = new BitOutputStream(bytesOut);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
View Full Code Here

    this.cf = 0;
    this.prevDocno = -1;

    try {
      bytesOut = new ByteArrayOutputStream();
      bitOut = new BitOutputStream(bytesOut);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
View Full Code Here

   * @param positions Array of positions for a term
   * @return Serialized positions (using gamma codes)
   */
  public static byte[] serializePositions(int[] positions) throws IOException {
    ByteArrayOutputStream b = new ByteArrayOutputStream();
    BitOutputStream t = new BitOutputStream(b);

    t.writeGamma(positions.length);

    for (int i = 0; i < positions.length; i++) {
      if (i == 0) {
        t.writeGamma(positions[0] + 1);
      } else {
        int pgap = positions[i] - positions[i - 1];
        t.writeGamma(pgap);
      }
    }

    t.padAndFlush();
    t.close();

    return b.toByteArray();
  }
View Full Code Here

      if (numTerms == 0)
        return;

      try {
        bytesOut = new ByteArrayOutputStream();
        bitsOut = new BitOutputStream(bytesOut);

        ArrayListOfInts positions;
        TermPositions tp = new TermPositions();
        String term;
View Full Code Here

      WritableUtils.writeVInt(out, numTerms);
      if (numTerms == 0)
        return;

      bytesOut = new ByteArrayOutputStream();
      bitsOut = new BitOutputStream(bytesOut);

      Iterator<Map.Entry<Integer, int[]>> it = termPositionsMap.entrySet().iterator();
      Map.Entry<Integer, int[]> posting = it.next();
      int[] positions = posting.getValue();
      TermPositions tp = new TermPositions();
View Full Code Here

      WritableUtils.writeVInt(out, numTerms);
      if (numTerms == 0)
        return;

      bytesOut = new ByteArrayOutputStream();
      bitsOut = new BitOutputStream(bytesOut);

      Iterator<Map.Entry<Integer, int[]>> it = termPositionsMap.entrySet().iterator();
      Map.Entry<Integer, int[]> posting = it.next();
      int[] positions = posting.getValue();
      TermPositions tp = new TermPositions();
View Full Code Here

   * @param positions Array of positions for a term
   * @return Serialized positions (using gamma codes)
   */
  public static byte[] serializePositions(int[] positions) throws IOException {
    ByteArrayOutputStream b = new ByteArrayOutputStream();
    BitOutputStream t = new BitOutputStream(b);

    t.writeGamma(positions.length);

    for (int i = 0; i < positions.length; i++) {
      if (i == 0) {
        t.writeGamma(positions[0] + 1);
      } else {
        int pgap = positions[i] - positions[i - 1];
        t.writeGamma(pgap);
      }
    }

    t.padAndFlush();
    t.close();

    return b.toByteArray();
  }
View Full Code Here

TOP

Related Classes of ivory.core.compression.BitOutputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.