@Override
 public void serialize(DataOutput out) throws IOException {
   // little endian
   for (long w : bitmap) {
     out.writeLong(Long.reverseBytes(w));
   }
 }
Example #2
0
  public void serialize(final DataOutput output) {
    try {
      output.writeDouble(maxError);
      output.writeDouble(alpha);
      output.writeLong(landmarkInSeconds);
      output.writeLong(min);
      output.writeLong(max);
      output.writeInt(totalNodeCount);

      postOrderTraversal(
          root,
          new Callback() {
            @Override
            public boolean process(Node node) {
              try {
                serializeNode(output, node);
              } catch (IOException e) {
                Throwables.propagate(e);
              }
              return true;
            }
          });
    } catch (IOException e) {
      Throwables.propagate(e);
    }
  }
Example #3
0
 // Used for internal Hadoop purposes.
 // Describes how to write this node across a network
 public void write(DataOutput out) throws IOException {
   out.writeLong(nodeid);
   out.writeDouble(pageRank);
   for (long n : outgoing) {
     out.writeLong(n);
   }
   out.writeLong(-1);
 }
Example #4
0
 public void writeTo(DataOutput out) throws Exception {
   out.writeInt(status);
   Bits.writeString(classname, out);
   Bits.writeString(name, out);
   out.writeLong(start_time);
   out.writeLong(stop_time);
   Bits.writeString(failure_type, out);
   Bits.writeString(failure_msg, out);
   Bits.writeString(stack_trace, out);
 }
  /*
   * NOTE:  This implementation assumes a maximum of 64 capability
   * bits per node class.  If this changes in the future, this
   * implementation will need to be updated.
   */
  private void writeCapabilities(DataOutput out) throws IOException {
    long capabilities = 0;
    long frequentCapabilities = 0;

    for (int i = 0; i < 64; i++) {
      if (node.getCapability(i)) capabilities |= (1L << i);
      if (!(node.getCapabilityIsFrequent(i))) frequentCapabilities |= (1L << i);
    }
    out.writeLong(capabilities);
    out.writeLong(frequentCapabilities);
  }
 @SuppressWarnings("deprecation")
 public void write(DataOutput out) throws IOException {
   out.writeLong(rpcVersion);
   UTF8.writeString(out, declaringClassProtocolName);
   UTF8.writeString(out, methodName);
   out.writeLong(clientVersion);
   out.writeInt(clientMethodsHash);
   out.writeInt(parameterClasses.length);
   for (int i = 0; i < parameterClasses.length; i++) {
     ObjectWritable.writeObject(out, parameters[i], parameterClasses[i], conf, true);
   }
 }
Example #7
0
 public void writeLong(long v) {
   try {
     dataOutput.writeLong(v);
   } catch (IOException ex) {
     throw new RuntimeException(ex.getMessage());
   }
 }
 ///////////////////////////////////////////
 // Writable
 ///////////////////////////////////////////
 public void write(DataOutput out) throws IOException {
   blockToken.write(out);
   out.writeBoolean(corrupt);
   out.writeLong(offset);
   b.write(out);
   out.writeInt(locs.length);
   for (int i = 0; i < locs.length; i++) {
     locs[i].write(out);
   }
 }
 /**
  * Writes the primitive value to the stream.
  *
  * @param out A stream to write to.
  * @param value A value to write.
  * @throws IOException If an I/O error occurs.
  */
 static void writePrimitive(DataOutput out, Object value) throws IOException {
   if (value instanceof Byte) out.writeByte((Byte) value);
   else if (value instanceof Short) out.writeShort((Short) value);
   else if (value instanceof Integer) out.writeInt((Integer) value);
   else if (value instanceof Long) out.writeLong((Long) value);
   else if (value instanceof Float) out.writeFloat((Float) value);
   else if (value instanceof Double) out.writeDouble((Double) value);
   else if (value instanceof Boolean) out.writeBoolean((Boolean) value);
   else if (value instanceof Character) out.writeChar((Character) value);
   else throw new IllegalArgumentException();
 }
Example #10
0
  /** Write a {@link Writable}, {@link String}, primitive type, or an array of the preceding. */
  public static void writeObject(
      DataOutput out, Object instance, Class declaredClass, Configuration conf) throws IOException {

    if (instance == null) { // null
      instance = new NullInstance(declaredClass, conf);
      declaredClass = Writable.class;
    }

    UTF8.writeString(out, declaredClass.getName()); // always write declared

    if (declaredClass.isArray()) { // array
      int length = Array.getLength(instance);
      out.writeInt(length);
      for (int i = 0; i < length; i++) {
        writeObject(out, Array.get(instance, i), declaredClass.getComponentType(), conf);
      }

    } else if (declaredClass == String.class) { // String
      UTF8.writeString(out, (String) instance);

    } else if (declaredClass.isPrimitive()) { // primitive type

      if (declaredClass == Boolean.TYPE) { // boolean
        out.writeBoolean(((Boolean) instance).booleanValue());
      } else if (declaredClass == Character.TYPE) { // char
        out.writeChar(((Character) instance).charValue());
      } else if (declaredClass == Byte.TYPE) { // byte
        out.writeByte(((Byte) instance).byteValue());
      } else if (declaredClass == Short.TYPE) { // short
        out.writeShort(((Short) instance).shortValue());
      } else if (declaredClass == Integer.TYPE) { // int
        out.writeInt(((Integer) instance).intValue());
      } else if (declaredClass == Long.TYPE) { // long
        out.writeLong(((Long) instance).longValue());
      } else if (declaredClass == Float.TYPE) { // float
        out.writeFloat(((Float) instance).floatValue());
      } else if (declaredClass == Double.TYPE) { // double
        out.writeDouble(((Double) instance).doubleValue());
      } else if (declaredClass == Void.TYPE) { // void
      } else {
        throw new IllegalArgumentException("Not a primitive: " + declaredClass);
      }
    } else if (declaredClass.isEnum()) { // enum
      UTF8.writeString(out, ((Enum) instance).name());
    } else if (Writable.class.isAssignableFrom(declaredClass)) { // Writable
      UTF8.writeString(out, instance.getClass().getName());
      ((Writable) instance).write(out);

    } else {
      throw new IOException("Can't write: " + instance + " as " + declaredClass);
    }
  }
Example #11
0
  private void serializeNode(DataOutput output, Node node) throws IOException {
    int flags = 0;
    if (node.left != null) {
      flags |= Flags.HAS_LEFT;
    }
    if (node.right != null) {
      flags |= Flags.HAS_RIGHT;
    }

    output.writeByte(flags);
    output.writeByte(node.level);
    output.writeLong(node.bits);
    output.writeDouble(node.weightedCount);
  }
  @Test
  public void testRead1SPP64BPS() throws IOException {
    // 1 sample per pixel, 64 bits per sample (gray)
    FastByteArrayOutputStream out = new FastByteArrayOutputStream(32);
    DataOutput dataOut = new DataOutputStream(out);
    dataOut.writeLong(0x00000000);
    dataOut.writeLong(81985529216486895L);
    dataOut.writeLong(81985529216486895L);
    dataOut.writeLong(-163971058432973790L);

    InputStream in =
        new HorizontalDeDifferencingStream(out.createInputStream(), 4, 1, 64, ByteOrder.BIG_ENDIAN);
    DataInput dataIn = new DataInputStream(in);

    // Row 1
    assertEquals(0, dataIn.readLong());
    assertEquals(81985529216486895L, dataIn.readLong());
    assertEquals(163971058432973790L, dataIn.readLong());
    assertEquals(0, dataIn.readLong());

    // EOF
    assertEquals(-1, in.read());
  }
Example #13
0
 @Override
 public void write(DataOutput output) throws IOException {
   Bytes.writeByteArray(output, name.getBytes());
   WritableUtils.writeVInt(output, type.ordinal());
   WritableUtils.writeVLong(output, sequenceNumber);
   output.writeLong(timeStamp);
   Bytes.writeByteArray(
       output, pkName == null ? ByteUtil.EMPTY_BYTE_ARRAY : Bytes.toBytes(pkName));
   WritableUtils.writeVInt(output, allColumns.size());
   for (int i = 0; i < allColumns.size(); i++) {
     PColumn column = allColumns.get(i);
     column.write(output);
   }
   stats.write(output);
 }
Example #14
0
 public void writeTo(DataOutput out) throws Exception {
   out.writeByte(type.ordinal());
   // We can't use Util.writeObject since it's size is limited to 2^15-1
   try {
     if (object instanceof Streamable) {
       out.writeShort(-1);
       Util.writeGenericStreamable((Streamable) object, out);
     } else {
       byte[] bytes = Util.objectToByteBuffer(object);
       out.writeInt(bytes.length);
       out.write(bytes);
     }
   } catch (IOException e) {
     throw e;
   } catch (Exception e) {
     throw new IOException("Exception encountered while serializing execution request", e);
   }
   out.writeLong(request);
 }
 /** Implement write of Writable */
 public void write(DataOutput out) throws IOException {
   out.writeLong(offset);
   out.writeLong(length);
   out.writeInt(names.length);
   for (int i = 0; i < names.length; i++) {
     Text name = new Text(names[i]);
     name.write(out);
   }
   out.writeInt(hosts.length);
   for (int i = 0; i < hosts.length; i++) {
     Text host = new Text(hosts[i]);
     host.write(out);
   }
   out.writeInt(topologyPaths.length);
   for (int i = 0; i < topologyPaths.length; i++) {
     Text host = new Text(topologyPaths[i]);
     host.write(out);
   }
 }
  @Override
  public void write(DataOutput out) throws IOException {
    int numCol = colType.length;
    boolean[] nullBits = new boolean[numCol];
    int[] colLength = new int[numCol];
    byte[] enumType = new byte[numCol];
    int[] padLength = new int[numCol];
    byte[] padbytes = new byte[8];

    /**
     * Compute the total payload and header length header = total length (4 byte), Version (2 byte),
     * Error (1 byte), #col (2 byte) col type array = #col * 1 byte null bit array = ceil(#col/8)
     */
    int datlen = 4 + 2 + 1 + 2;
    datlen += numCol;
    datlen += getNullByteArraySize(numCol);

    for (int i = 0; i < numCol; i++) {
      /* Get the enum type */
      DBType coldbtype;
      switch (DataType.get(colType[i])) {
        case BIGINT:
          coldbtype = DBType.BIGINT;
          break;
        case BOOLEAN:
          coldbtype = DBType.BOOLEAN;
          break;
        case FLOAT8:
          coldbtype = DBType.FLOAT8;
          break;
        case INTEGER:
          coldbtype = DBType.INTEGER;
          break;
        case REAL:
          coldbtype = DBType.REAL;
          break;
        case SMALLINT:
          coldbtype = DBType.SMALLINT;
          break;
        case BYTEA:
          coldbtype = DBType.BYTEA;
          break;
        default:
          coldbtype = DBType.TEXT;
      }
      enumType[i] = (byte) (coldbtype.ordinal());

      /* Get the actual value, and set the null bit */
      if (colValue[i] == null) {
        nullBits[i] = true;
        colLength[i] = 0;
      } else {
        nullBits[i] = false;

        /*
         * For fixed length type, we get the fixed length.
         * For var len binary format, the length is in the col value.
         * For text format, we must convert encoding first.
         */
        if (!coldbtype.isVarLength()) {
          colLength[i] = coldbtype.getTypeLength();
        } else if (!isTextForm(colType[i])) {
          colLength[i] = ((byte[]) colValue[i]).length;
        } else {
          colLength[i] = ((String) colValue[i]).getBytes(CHARSET).length;
        }

        /* calculate and add the type alignment padding */
        padLength[i] = roundUpAlignment(datlen, coldbtype.getAlignment()) - datlen;
        datlen += padLength[i];

        /* for variable length type, we add a 4 byte length header */
        if (coldbtype.isVarLength()) {
          datlen += 4;
        }
      }
      datlen += colLength[i];
    }

    /*
     * Add the final alignment padding for the next record
     */
    int endpadding = roundUpAlignment(datlen, 8) - datlen;
    datlen += endpadding;

    /* Construct the packet header */
    out.writeInt(datlen);
    out.writeShort(VERSION);
    out.writeByte(errorFlag);
    out.writeShort(numCol);

    /* Write col type */
    for (int i = 0; i < numCol; i++) {
      out.writeByte(enumType[i]);
    }

    /* Nullness */
    byte[] nullBytes = boolArrayToByteArray(nullBits);
    out.write(nullBytes);

    /* Column Value */
    for (int i = 0; i < numCol; i++) {
      if (!nullBits[i]) {
        /* Pad the alignment byte first */
        if (padLength[i] > 0) {
          out.write(padbytes, 0, padLength[i]);
        }

        /* Now, write the actual column value */
        switch (DataType.get(colType[i])) {
          case BIGINT:
            out.writeLong(((Long) colValue[i]));
            break;
          case BOOLEAN:
            out.writeBoolean(((Boolean) colValue[i]));
            break;
          case FLOAT8:
            out.writeDouble(((Double) colValue[i]));
            break;
          case INTEGER:
            out.writeInt(((Integer) colValue[i]));
            break;
          case REAL:
            out.writeFloat(((Float) colValue[i]));
            break;
          case SMALLINT:
            out.writeShort(((Short) colValue[i]));
            break;

            /* For BYTEA format, add 4byte length header at the beginning  */
          case BYTEA:
            out.writeInt(colLength[i]);
            out.write((byte[]) colValue[i]);
            break;

            /* For text format, add 4byte length header. string is already '\0' terminated */
          default:
            {
              out.writeInt(colLength[i]);
              byte[] data = ((String) colValue[i]).getBytes(CHARSET);
              out.write(data);
              break;
            }
        }
      }
    }

    /* End padding */
    out.write(padbytes, 0, endpadding);
  }
Example #17
0
 void a(DataOutput dataoutput) {
   dataoutput.writeLong(a);
 }
Example #18
0
 /////////////////////////////////////
 // Writable
 /////////////////////////////////////
 public void write(DataOutput out) throws IOException {
   out.writeLong(genstamp);
 }
Example #19
0
 // ///////////////////////////////////
 // Writable
 // ///////////////////////////////////
 public void write(DataOutput out) throws IOException {
   out.writeLong(blockId);
   out.writeLong(numBytes);
   out.writeLong(generationStamp);
 }
Example #20
0
 void writeTagContents(DataOutput dataoutput) throws IOException {
   dataoutput.writeLong(longValue);
 }
Example #21
0
 void func_735_a(DataOutput p_735_1_) throws IOException {
   p_735_1_.writeLong(field_1095_a);
 }
Example #22
0
 @Override
 public void writeTo(DataOutput out) throws Exception {
   super.writeTo(out);
   out.writeLong(threadId);
 }