Exemplo n.º 1
0
 public static void writeFixedString(String s, int size, DataOutput out) throws IOException {
   for (int i = 0; i < size; i++) {
     char ch = 0;
     if (i < s.length()) ch = s.charAt(i);
     out.writeChar(ch);
   }
 }
Exemplo n.º 2
0
 public void writeChar(int v) {
   try {
     dataOutput.writeChar(v);
   } catch (IOException ex) {
     throw new RuntimeException(ex.getMessage());
   }
 }
Exemplo n.º 3
0
 public void write(DataOutput out) {
   try {
     out.writeChar(getSuit());
     out.writeChar(getRank());
   } catch (IOException e) {
     e.printStackTrace(System.out);
   }
 }
Exemplo n.º 4
0
 @Override
 public void writeChar(int v) {
   try {
     output.writeChar(v);
   } catch (IOException impossible) {
     throw new AssertionError(impossible);
   }
 }
 /**
  * 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();
 }
Exemplo n.º 6
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);
    }
  }
Exemplo n.º 7
0
  public void write(DataOutput out) throws IOException {
    Set<String> mapKeys;

    out.writeInt(this.state_type.val);
    out.writeInt(this.state_mapred.val);
    out.writeInt(this.state_hdfs.val);
    out.writeInt(this.fsm_type.val);
    out.writeChar(DELIM);
    out.writeInt(state_name.length());
    if (state_name.length() > 0) out.writeUTF(state_name);
    out.writeInt(unique_id.length());
    if (unique_id.length() > 0) out.writeUTF(unique_id);
    out.writeInt(timestamp.length());
    if (timestamp.length() > 0) out.writeUTF(timestamp);
    out.writeInt(time_start.length());
    if (time_start.length() > 0) out.writeUTF(time_start);
    out.writeInt(time_end.length());
    if (time_end.length() > 0) out.writeUTF(time_end);
    out.writeInt(host_exec.length());
    if (host_exec.length() > 0) out.writeUTF(host_exec);
    out.writeInt(host_other.length());
    if (host_other.length() > 0) out.writeUTF(host_other);
    out.writeInt(time_orig_epoch.length());
    if (time_orig_epoch.length() > 0) out.writeUTF(time_orig_epoch);
    out.writeInt(time_orig.length());
    if (time_orig.length() > 0) out.writeUTF(time_orig);
    out.writeInt(job_id.length());
    if (job_id.length() > 0) out.writeUTF(job_id);
    out.writeInt(identifier.length());
    if (identifier.length() > 0) out.writeUTF(identifier);

    mapKeys = this.add_info.keySet();
    out.writeInt(mapKeys.size());

    for (Entry<String, String> entry : this.add_info.entrySet()) {
      String value = entry.getValue();
      if (value.length() > 0) {
        out.writeUTF(entry.getKey());
        out.writeInt(value.length());
        out.writeUTF(value);
      } else {
        out.writeUTF("NULL");
        out.writeInt(0);
      }
    }
  }
 @Override
 public void writeChar(int v) throws IOException {
   dataOutput.writeChar(v);
 }
Exemplo n.º 9
0
 public void writeChar(int v) throws IOException {
   out.writeChar(v);
 }
Exemplo n.º 10
0
 public void writeGenotype(final EvolutionState state, final DataOutput dataOutput)
     throws IOException {
   dataOutput.writeInt(genome.length);
   for (int x = 0; x < genome.length; x++) dataOutput.writeChar(genome[x]);
 }
Exemplo n.º 11
0
 public static void writeFixedString(DataOutput out, int length, String s) throws IOException {
   for (int i = 0; i < length; i++) {
     if (i < s.length()) out.writeChar(s.charAt(i)); // write char
     else out.writeChar(0); // write Unicode zero
   }
 }