Java Code Examples for java.io.DataOutput#writeChar()

The following examples show how to use java.io.DataOutput#writeChar() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DynamoDBItemWritable.java    From emr-dynamodb-connector with Apache License 2.0 6 votes vote down vote up
@Override
public void write(DataOutput out) throws IOException {
  String whole = writeStream();
  int chunkSize = 1 << 14;
  int chunks = whole.length() / chunkSize;
  if (whole.length() % chunkSize != 0) {
    chunks += 1;
  }

  out.writeChar(FIRST_MAGIC_BYTES);
  out.write(new byte[]{NEXT_MAGIC_BYTE});

  out.writeInt(chunks);
  for (int c = 0; c < chunks; c++) {
    String chunk = whole.substring(c * chunkSize, Math.min((c + 1) * chunkSize, whole.length()));
    out.writeUTF(chunk);
  }
}
 
Example 2
Source File: ColGroupDDC2.java    From systemds with Apache License 2.0 6 votes vote down vote up
@Override
public void write(DataOutput out) throws IOException {
	int numCols = getNumCols();
	int numVals = getNumValues();
	out.writeInt(_numRows);
	out.writeInt(numCols);
	out.writeInt(numVals);

	// write col indices
	for(int i = 0; i < _colIndexes.length; i++)
		out.writeInt(_colIndexes[i]);

	// write distinct values
	double[] values = getValues();
	for(int i = 0; i < values.length; i++)
		out.writeDouble(values[i]);

	// write data
	for(int i = 0; i < _numRows; i++)
		out.writeChar(_data[i]);
}
 
Example 3
Source File: Row.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Write the contents of this Row to the given output stream.
 * 
 * @param os the output stream
 * @exception IOException if an I/O error occurs
 */
public void store(DataOutput os) throws IOException {
  os.writeInt(cells.size());
  Iterator<Character> i = cells.keySet().iterator();
  for (; i.hasNext();) {
    Character c = i.next();
    Cell e = at(c);
    if (e.cmd < 0 && e.ref < 0) {
      continue;
    }
    
    os.writeChar(c.charValue());
    os.writeInt(e.cmd);
    os.writeInt(e.cnt);
    os.writeInt(e.ref);
    os.writeInt(e.skip);
  }
}
 
Example 4
Source File: ColGroupDDC2.java    From systemds with Apache License 2.0 6 votes vote down vote up
@Override
public void write(DataOutput out) throws IOException {
	int numCols = getNumCols();
	int numVals = getNumValues();
	out.writeInt(_numRows);
	out.writeInt(numCols);
	out.writeInt(numVals);

	// write col indices
	for(int i = 0; i < _colIndexes.length; i++)
		out.writeInt(_colIndexes[i]);

	// write distinct values
	for(int i = 0; i < _values.length; i++)
		out.writeDouble(_values[i]);

	// write data
	for(int i = 0; i < _numRows; i++)
		out.writeChar(_data[i]);
}
 
Example 5
Source File: SummationWritable.java    From big-c with Apache License 2.0 5 votes vote down vote up
/** Write ArithmeticProgression to DataOutput */
private static void write(ArithmeticProgression ap, DataOutput out
    ) throws IOException {
  out.writeChar(ap.symbol);
  out.writeLong(ap.value);
  out.writeLong(ap.delta);
  out.writeLong(ap.limit);
}
 
Example 6
Source File: VariantContextCodec.java    From Hadoop-BAM with MIT License 5 votes vote down vote up
private static void encodeAttrVal(final DataOutput out, final Object v)
	throws IOException
{
	if (v instanceof Integer) {
		out.writeByte(AttrType.INT.toByte());
		out.writeInt ((Integer)v);
	} else if (v instanceof Float) {
		out.writeByte (AttrType.FLOAT.toByte());
		out.writeFloat((Float)v);
	} else if (v instanceof Double) {
		out.writeByte  (AttrType.DOUBLE.toByte());
		out.writeDouble((Double)v);
	} else if (v instanceof Boolean) {
		out.writeByte   (AttrType.BOOL.toByte());
		out.writeBoolean((Boolean)v);
	} else if (v instanceof Character) {
		out.writeByte(AttrType.CHAR.toByte());
		out.writeChar((Character)v);

	} else if (v instanceof List) {
		encodeAttrVal(out, ((List)v).toArray());

	} else if (v != null && v.getClass().isArray()) {
		out.writeByte(AttrType.ARRAY.toByte());
		final int length = Array.getLength(v);
		out.writeInt(length);
		for (int i = 0; i < length; ++i)
			encodeAttrVal(out, Array.get(v, i));

	} else {
		out.writeByte(AttrType.STRING.toByte());
		if (v == null)
			out.writeInt(0);
		else {
			final byte[] b = v.toString().getBytes("UTF-8");
			out.writeInt(b.length);
			out.write   (b);
		}
	}
}
 
Example 7
Source File: DataSerializer.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Writes a primitive  <code>char</code> to a
 * <code>DataOutput</code>.
 *
 * @throws IOException
 *         A problem occurs while writing to <code>out</code>
 *
 * @see DataOutput#writeChar
 * @since 5.1
 */
public static void writePrimitiveChar(char value, DataOutput out)
  throws IOException {

  InternalDataSerializer.checkOut(out);

  if (DEBUG) {
    InternalDataSerializer.logger.info( LocalizedStrings.DEBUG, "Writing Char " + value);
  }

  out.writeChar(value);
}
 
Example 8
Source File: DataSerializer.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Writes an instance of <code>Character</code> to a
 * <code>DataOutput</code>.
 *
 * @throws IOException
 *         A problem occurs while writing to <code>out</code>
 * @throws NullPointerException if value is null.
 *
 * @see #readCharacter
 */
public static void writeCharacter(Character value, DataOutput out)
  throws IOException {

  InternalDataSerializer.checkOut(out);

  if (DEBUG) {
    InternalDataSerializer.logger.info( LocalizedStrings.DEBUG, "Writing Character " + value);
  }

  out.writeChar(value.charValue());
}
 
Example 9
Source File: MapLiteSerializer.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public static void writeCharacter(Character value, DataOutput output) throws IOException
{
	if (value == null) {
		output.writeChar(0);
	} else {
		output.writeChar(value);
	}
}
 
Example 10
Source File: IOUtils.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
public static void writeString(@Nullable final String s, final DataOutput out)
        throws IOException {
    if (s == null) {
        out.writeInt(-1);
        return;
    }
    final int len = s.length();
    out.writeInt(len);
    for (int i = 0; i < len; i++) {
        int v = s.charAt(i);
        out.writeChar(v);
    }
}
 
Example 11
Source File: DataSerializer.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Writes a primitive  <code>char</code> to a
 * <code>DataOutput</code>.
 *
 * @throws IOException
 *         A problem occurs while writing to <code>out</code>
 *
 * @see DataOutput#writeChar
 * @since 5.1
 */
public static void writePrimitiveChar(char value, DataOutput out)
  throws IOException {

  InternalDataSerializer.checkOut(out);

  if (DEBUG) {
    InternalDataSerializer.logger.info( LocalizedStrings.DEBUG, "Writing Char " + value);
  }

  out.writeChar(value);
}
 
Example 12
Source File: MapLiteSerializer.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public static void writeCharacter(Character value, DataOutput output) throws IOException
{
	if (value == null) {
		output.writeChar(0);
	} else {
		output.writeChar(value);
	}
}
 
Example 13
Source File: IOUtils.java    From btree4j with Apache License 2.0 5 votes vote down vote up
public static void writeString(@Nullable final String s, final DataOutput out)
        throws IOException {
    if (s == null) {
        out.writeInt(-1);
        return;
    }
    final int len = s.length();
    out.writeInt(len);
    for (int i = 0; i < len; i++) {
        int v = s.charAt(i);
        out.writeChar(v);
    }
}
 
Example 14
Source File: SummationWritable.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/** Write ArithmeticProgression to DataOutput */
private static void write(ArithmeticProgression ap, DataOutput out
    ) throws IOException {
  out.writeChar(ap.symbol);
  out.writeLong(ap.value);
  out.writeLong(ap.delta);
  out.writeLong(ap.limit);
}
 
Example 15
Source File: DeltaObject.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
protected void _toDelta(DataOutput out) throws IOException {
   Log.getLogWriter().info("In DeltaObject.toDelta, for " + this + "\n" + "with DataOutput " + out);
   DeltaObserver.addToDeltaKey(extra);

   // for validation later, encode with a toDelta id number
   long toDeltaIdNumber = DeltaPropagationBB.getBB().getSharedCounters().incrementAndRead(DeltaPropagationBB.toDeltaIdNumber);
   out.writeLong(toDeltaIdNumber);
   Log.getLogWriter().info("Wrote toDeltaIdNumber " + toDeltaIdNumber);

   out.writeBoolean(aPrimitiveLongChanged);
   if (aPrimitiveLongChanged) {
      out.writeLong(aPrimitiveLong);
      Log.getLogWriter().info("Wrote changed field aPrimitiveLong " + aPrimitiveLong);
   }
   out.writeBoolean(aPrimitiveIntChanged);
   if (aPrimitiveIntChanged) {
      out.writeInt(aPrimitiveInt);
      Log.getLogWriter().info("Wrote changed field aPrimitiveInt " + aPrimitiveInt);
   }
   out.writeBoolean(aPrimitiveShortChanged);
   if (aPrimitiveShortChanged) {
      out.writeShort(aPrimitiveShort);
      Log.getLogWriter().info("Wrote changed field aPrimitiveShort " + aPrimitiveShort);
   }
   out.writeBoolean(aPrimitiveFloatChanged);
   if (aPrimitiveFloatChanged) {
      out.writeFloat(aPrimitiveFloat);
      Log.getLogWriter().info("Wrote changed field aPrimitiveFloat " + aPrimitiveFloat);
   }
   out.writeBoolean(aPrimitiveDoubleChanged);
   if (aPrimitiveDoubleChanged) {
      out.writeDouble(aPrimitiveDouble);
      Log.getLogWriter().info("Wrote changed field aPrimitiveDouble " + aPrimitiveDouble);
   }
   out.writeBoolean(aPrimitiveByteChanged);
   if (aPrimitiveByteChanged) {
      out.writeByte(aPrimitiveByte);
      Log.getLogWriter().info("Wrote changed field aPrimitiveByte " + aPrimitiveByte);
   }
   out.writeBoolean(aPrimitiveCharChanged);
   if (aPrimitiveCharChanged) {
      out.writeChar(aPrimitiveChar);
      Log.getLogWriter().info("Wrote changed field aPrimitiveChar " + aPrimitiveChar);
   }
   out.writeBoolean(aPrimitiveBooleanChanged);
   if (aPrimitiveBooleanChanged) {
      out.writeBoolean(aPrimitiveBoolean);
      Log.getLogWriter().info("Wrote changed field aPrimitiveBoolean " + aPrimitiveBoolean);
   }
   out.writeBoolean(aByteArrayChanged);
   if (aByteArrayChanged) {
      out.writeInt(aByteArray.length);
      out.write(aByteArray);
      Log.getLogWriter().info("Wrote changed field aByteArray of length " + aByteArray.length);
   }
   out.writeBoolean(aStringChanged);
   if (aStringChanged) {
      out.writeInt(aString.length());
      out.writeBytes(aString);
      Log.getLogWriter().info("Wrote changed field aString " + aString);
   }
   out.writeInt(END_SIGNAL.length());
   out.writeBytes(END_SIGNAL);
   Log.getLogWriter().info("Wrote end signal: " + END_SIGNAL);
   Log.getLogWriter().info("Done writing in DeltaObject.toDelta for " + this);
}
 
Example 16
Source File: ArrayPrimitiveWritable.java    From big-c with Apache License 2.0 4 votes vote down vote up
private void writeCharArray(DataOutput out) throws IOException {
  char[] v = (char[]) value;
  for (int i = 0; i < length; i++)
    out.writeChar(v[i]);
}
 
Example 17
Source File: CharSerializer.java    From util with Apache License 2.0 4 votes vote down vote up
@Override
public void write(final Character val, final DataOutput out) throws IOException {
    out.writeChar(val);
}
 
Example 18
Source File: HadoopDataStreamSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @param out Data output.
 * @throws IOException On error.
 */
private void write(DataOutput out) throws IOException {
    out.writeBoolean(false);
    out.writeBoolean(true);
    out.writeBoolean(false);
    out.write(17);
    out.write(121);
    out.write(0xfafa);
    out.writeByte(17);
    out.writeByte(121);
    out.writeByte(0xfafa);
    out.writeChar('z');
    out.writeChar('o');
    out.writeChar('r');
    out.writeShort(100);
    out.writeShort(Short.MIN_VALUE);
    out.writeShort(Short.MAX_VALUE);
    out.writeShort(65535);
    out.writeShort(65536); // 0
    out.writeInt(Integer.MAX_VALUE);
    out.writeInt(Integer.MIN_VALUE);
    out.writeInt(-1);
    out.writeInt(0);
    out.writeInt(1);
    out.writeFloat(0.33f);
    out.writeFloat(0.5f);
    out.writeFloat(-0.7f);
    out.writeFloat(Float.MAX_VALUE);
    out.writeFloat(Float.MIN_VALUE);
    out.writeFloat(Float.MIN_NORMAL);
    out.writeFloat(Float.POSITIVE_INFINITY);
    out.writeFloat(Float.NEGATIVE_INFINITY);
    out.writeFloat(Float.NaN);
    out.writeDouble(-12312312.3333333336666779);
    out.writeDouble(123123.234);
    out.writeDouble(Double.MAX_VALUE);
    out.writeDouble(Double.MIN_VALUE);
    out.writeDouble(Double.MIN_NORMAL);
    out.writeDouble(Double.NEGATIVE_INFINITY);
    out.writeDouble(Double.POSITIVE_INFINITY);
    out.writeDouble(Double.NaN);
    out.writeLong(Long.MAX_VALUE);
    out.writeLong(Long.MIN_VALUE);
    out.writeLong(0);
    out.writeLong(-1L);
    out.write(new byte[] {1, 2, 3});
    out.write(new byte[] {0, 1, 2, 3}, 1, 2);
    out.writeUTF("mom washes rum");
}
 
Example 19
Source File: CharType.java    From stratosphere with Apache License 2.0 4 votes vote down vote up
@Override
public void write(DataOutput out) throws IOException {
	out.writeChar(this.value);
}
 
Example 20
Source File: CharValue.java    From stratosphere with Apache License 2.0 4 votes vote down vote up
@Override
public void write(DataOutput out) throws IOException {
	out.writeChar(this.value);
}