Package java.io

Examples of java.io.DataInput


            }
        }

        public static CompressedSegment readFrom(final byte[] in) throws IOException {
            FastByteArrayInputStream bis = new FastByteArrayInputStream(in);
            DataInput dis = new DataInputStream(bis);
            int totalEntries = dis.readInt();
            int bitwidth = dis.readByte();
            int firstException = dis.readInt();
            int len = dis.readInt();
            byte[] b = new byte[len];
            dis.readFully(b, 0, len);
            FastByteArrayInputStream codesIs = new FastByteArrayInputStream(b);
            BitInputStream codesBis = new BitInputStream(codesIs);
            int[] codes = new int[totalEntries];
            unpack(codesBis, bitwidth, codes, totalEntries);
            int exceptions = dis.readShort();
            CharArrayList exceptionList = new CharArrayList(exceptions);
            for(int i = 0; i < exceptions; i++) {
                char c = dis.readChar();
                exceptionList.add(c);
            }
            return new CompressedSegment(totalEntries, bitwidth, firstException, codes, exceptionList);
        }
View Full Code Here


      try {
        if (blockType == BlockType.GENERAL_BLOOM_META) {
          if (this.generalBloomFilter != null)
            return; // Bloom has been loaded

          DataInput bloomMeta = reader.getGeneralBloomFilterMetadata();
          if (bloomMeta != null) {
            // sanity check for NONE Bloom filter
            if (bloomFilterType == BloomType.NONE) {
              throw new IOException(
                  "valid bloom filter type not found in FileInfo");
            } else {
              generalBloomFilter = BloomFilterFactory.createFromMeta(bloomMeta,
                  reader);
              LOG.info("Loaded " + bloomFilterType.toString() + " ("
                  + generalBloomFilter.getClass().getSimpleName()
                  + ") metadata for " + reader.getName());
            }
          }
        } else if (blockType == BlockType.DELETE_FAMILY_BLOOM_META) {
          if (this.deleteFamilyBloomFilter != null)
            return; // Bloom has been loaded

          DataInput bloomMeta = reader.getDeleteBloomFilterMetadata();
          if (bloomMeta != null) {
            deleteFamilyBloomFilter = BloomFilterFactory.createFromMeta(
                bloomMeta, reader);
            LOG.info("Loaded Delete Family Bloom ("
                + deleteFamilyBloomFilter.getClass().getSimpleName()
View Full Code Here

            dataOut.writeByte(NULL_TYPE);
        }
    }

    public Object unmarshal(DataInput dis) throws IOException {
        DataInput dataIn = dis;
        if (!sizePrefixDisabled) {
            int size = dis.readInt();
            if (size > maxFrameSize) {
                throw new IOException(
                        "Frame size of " + (size / (1024 * 1024)) +
View Full Code Here

        ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
        DataOutput out = new DataOutputStream(byteStream);
        headers.write(out);
       
        HttpHeaders newHeaders = new HttpHeaders();
        DataInput in = new DataInputStream(new ByteArrayInputStream(byteStream.toByteArray()));
        newHeaders.readFields(in);
       
        assertEquals("value1", newHeaders.getFirst("key1"));
        List<String> values = newHeaders.getAll("key1");
        assertEquals(2, values.size());
View Full Code Here

     *
     * @param input the data input for this page
     * @throws java.io.IOException if an exception is thrown
     */
    protected void readMessage(InputStream input) throws IOException {
        final DataInput di = new DataInputStream(input);

        readRequestLine(di);
        readHeaders(di);
        readBody(di);

View Full Code Here

        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        DataOutput out=new DataOutputStream(bos);
        wn1.write(out);
        byte[] result=bos.toByteArray();
        ByteArrayInputStream bis = new ByteArrayInputStream(result);
        DataInput in=new DataInputStream(bis);
        wn2.readFields(in);
    }
View Full Code Here

   * @param bytes the array of bytes
   * @param start the index into the array to start grabbing bytes
   * @return the integer constructed from the four bytes in the array
   */
  private int hashToInt(byte[] bytes, int start) {
    DataInput input = new DataInputStream(
        new ByteArrayInputStream(bytes, start, bytes.length - start));
    int val;
    try {
      val = input.readInt();
    } catch (IOException e) {
      throw new IllegalStateException(String.valueOf(e));
    }
    return val;
  }
View Full Code Here

      return this;
    }
   
    public void init(boolean mayRequireData) throws IOException {
      dis = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
      DataInput di = dis;
      dis.mark(10);
      versionField = di.readInt();
      dis.reset();
      final int INLINEDATA = 1 << 16;
      inlineData = (versionField & INLINEDATA) != 0;
     
      dataStream = null;
View Full Code Here

      return dis.available() > 0;
    }
   
    public void readNext() throws IOException, DataFormatException {
      entryIndex++;
      DataInput di = dis;
      long l = di.readLong();
      offset = entryIndex == 0 ? 0 : (l >>> 16);
      flags = (int) (l & 0x0FFFF);
      compressedLen = di.readInt();
      actualLen = di.readInt();
      baseRevision = di.readInt();
      linkRevision = di.readInt();
      parent1Revision = di.readInt();
      parent2Revision = di.readInt();
      di.readFully(nodeid, 1, 20);
      dis.skipBytes(12);
      // CAN'T USE skip() here without extra precautions. E.g. I ran into situation when
      // buffer was 8192 and BufferedInputStream was at position 8182 before attempt to skip(12).
      // BIS silently skips available bytes and leaves me two extra bytes that ruin the rest of the code.
      data = new byte[compressedLen];
      if (inlineData) {
        di.readFully(data);
      } else if (needRevData) {
        dataStream.position(offset);
        dataStream.read(ByteBuffer.wrap(data));
      }
      if (needRevData) {
View Full Code Here

    assertEquals(root, readNode());
  }

  Node readNode() throws IOException {
    ByteArrayInputStream byteInStream = new ByteArrayInputStream(byteOutStream.toByteArray());
    DataInput in = new DataInputStream(byteInStream);
    return Node.read(in);
  }
View Full Code Here

TOP

Related Classes of java.io.DataInput

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.