Package org.apache.hadoop.record

Examples of org.apache.hadoop.record.Buffer


    list.add(123456789L);
    Map<Object, Object> map = new HashMap<Object, Object>();
    map.put("one", 1);
    map.put("vector", vector);
    Object[] objects = new Object[] {
      new Buffer(new byte[] { 1, 2, 3, 4 }),
      (byte) 123, true, 12345, 123456789L, (float) 1.2, 1.234,
      "random string", vector, list, map
    };
    byte[] appSpecificBytes = new byte[] { 1, 2, 3 };

    FileOutputStream ostream = new FileOutputStream(tmpfile);
    DataOutputStream dostream = new DataOutputStream(ostream);
    TypedBytesOutput out = new TypedBytesOutput(dostream);
    for (Object obj : objects) {
      out.write(obj);
    }
    out.writeBytes(appSpecificBytes, 100);
    dostream.close();
    ostream.close();

    FileInputStream istream = new FileInputStream(tmpfile);
    DataInputStream distream = new DataInputStream(istream);
    TypedBytesInput in = new TypedBytesInput(distream);
    for (Object obj : objects) {
      assertEquals(obj, in.read());
    }
    assertEquals(new Buffer(appSpecificBytes), in.read());
    distream.close();
    istream.close();

    istream = new FileInputStream(tmpfile);
    distream = new DataInputStream(istream);
    in = new TypedBytesInput(distream);
    for (Object obj : objects) {
      byte[] bytes = in.readRaw();
      ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
      DataInputStream dis = new DataInputStream(bais);
      assertEquals(obj, (new TypedBytesInput(dis)).read());
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      TypedBytesOutput tbout = new TypedBytesOutput(new DataOutputStream(baos));
      tbout.writeRaw(bytes);
      bais = new ByteArrayInputStream(bytes);
      dis = new DataInputStream(bais);
      assertEquals(obj, (new TypedBytesInput(dis)).read());
    }
    byte[] rawBytes = in.readRaw();
    assertEquals(new Buffer(appSpecificBytes),
      new Buffer(rawBytes, 5, rawBytes.length - 5));
    distream.close();
    istream.close();
  }
View Full Code Here


    r1.setFloatVal(3.145F);
    r1.setDoubleVal(1.5234);
    r1.setIntVal(-4567);
    r1.setLongVal(-2367L);
    r1.setStringVal("random text");
    r1.setBufferVal(new Buffer());
    r1.setVectorVal(new ArrayList<String>());
    r1.setMapVal(new TreeMap<String, String>());
    RecRecord0 r0 = new RecRecord0();
    r0.setStringVal("other random text");
    r1.setRecordVal(r0);
View Full Code Here

    r1.setFloatVal(3.145F);
    r1.setDoubleVal(1.5234);
    r1.setIntVal(-4567);
    r1.setLongVal(-2367L);
    r1.setStringVal("random text");
    r1.setBufferVal(new Buffer());
    r1.setVectorVal(new ArrayList<String>());
    r1.setMapVal(new TreeMap<String, String>());
    RecRecord0 r0 = new RecRecord0();
    r0.setStringVal("other random text");
    r1.setRecordVal(r0);
View Full Code Here

    synchronized (this) {
      if (this.mapFields == null) {
        this.mapFields = new TreeMap<String, org.apache.hadoop.record.Buffer>();
      }
    }
    this.mapFields.put(key, new Buffer(value.getBytes()));
  }
View Full Code Here

    return in.readBool();
  }

  public Buffer readBuffer(String tag) throws IOException {
    in.skipType();
    return new Buffer(in.readBytes());
  }
View Full Code Here

      code = in.readUnsignedByte();
    } catch (EOFException eof) {
      return null;
    }
    if (code == Type.BYTES.code) {
      return new Buffer(readBytes());
    } else if (code == Type.BYTE.code) {
      return readByte();
    } else if (code == Type.BOOL.code) {
      return readBool();
    } else if (code == Type.INT.code) {
      return readInt();
    } else if (code == Type.SHORT.code) {
      return readShort();
    } else if (code == Type.LONG.code) {
      return readLong();
    } else if (code == Type.FLOAT.code) {
      return readFloat();
    } else if (code == Type.DOUBLE.code) {
      return readDouble();
    } else if (code == Type.STRING.code) {
      return readString();
    } else if (code == Type.VECTOR.code) {
      return readVector();
    } else if (code == Type.LIST.code) {
      return readList();
    } else if (code == Type.MAP.code) {
      return readMap();
    } else if (code == Type.MARKER.code) {
      return null;
    } else if (50 <= code && code <= 200) { // application-specific typecodes
      return new Buffer(readBytes());
    } else {
      throw new RuntimeException("unknown type");
    }
  }
View Full Code Here

   * Reads the raw bytes following a <code>Type.VECTOR</code> code.
   * @return the obtained bytes sequence
   * @throws IOException
   */
  public byte[] readRawVector() throws IOException {
    Buffer buffer = new Buffer();
    int length = readVectorHeader();
    buffer.append(new byte[] {
      (byte) Type.VECTOR.code,
      (byte) (0xff & (length >> 24)), (byte) (0xff & (length >> 16)),
      (byte) (0xff & (length >> 8)), (byte) (0xff & length)
    });
    for (int i = 0; i < length; i++) {
      buffer.append(readRaw());
    }
    return buffer.get();
  }
View Full Code Here

   * Reads the raw bytes following a <code>Type.LIST</code> code.
   * @return the obtained bytes sequence
   * @throws IOException
   */
  public byte[] readRawList() throws IOException {
    Buffer buffer = new Buffer(new byte[] { (byte) Type.LIST.code });
    byte[] bytes = readRaw();
    while (bytes != null) {
      buffer.append(bytes);
      bytes = readRaw();
    }
    buffer.append(new byte[] { (byte) Type.MARKER.code });
    return buffer.get();
  }
View Full Code Here

   * Reads the raw bytes following a <code>Type.MAP</code> code.
   * @return the obtained bytes sequence
   * @throws IOException
   */
  public byte[] readRawMap() throws IOException {
    Buffer buffer = new Buffer();
    int length = readMapHeader();
    buffer.append(new byte[] {
      (byte) Type.MAP.code,
      (byte) (0xff & (length >> 24)), (byte) (0xff & (length >> 16)),
      (byte) (0xff & (length >> 8)), (byte) (0xff & length)
    });
    for (int i = 0; i < length; i++) {
      buffer.append(readRaw());
      buffer.append(readRaw());
    }
    return buffer.get();
  }
View Full Code Here

      if (this.mapFields == null)
      {
        this.mapFields = new TreeMap<String,org.apache.hadoop.record.Buffer>();
      }
    }
    this.mapFields.put(key, new Buffer(value.getBytes()));
  }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.record.Buffer

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.