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

The following examples show how to use java.io.DataOutput#writeShort() . 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: FSImageSerialization.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Serialize a {@link INodeDirectory}
 * @param node The node to write
 * @param out The {@link DataOutput} where the fields are written
 */
public static void writeINodeDirectory(INodeDirectory node, DataOutput out)
    throws IOException {
  writeLocalName(node, out);
  out.writeLong(node.getId());
  out.writeShort(0);  // replication
  out.writeLong(node.getModificationTime());
  out.writeLong(0);   // access time
  out.writeLong(0);   // preferred block size
  out.writeInt(-1);   // # of blocks

  writeQuota(node.getQuotaCounts(), out);

  if (node.isSnapshottable()) {
    out.writeBoolean(true);
  } else {
    out.writeBoolean(false);
    out.writeBoolean(node.isWithSnapshot());
  }

  writePermissionStatus(node, out);
}
 
Example 2
Source File: HeartbeatResponse.java    From hadoop-gpu with Apache License 2.0 6 votes vote down vote up
public void write(DataOutput out) throws IOException {
  out.writeShort(responseId);
  out.writeInt(heartbeatInterval);
  if (actions == null) {
    WritableUtils.writeVInt(out, 0);
  } else {
    WritableUtils.writeVInt(out, actions.length);
    for (TaskTrackerAction action : actions) {
      WritableUtils.writeEnum(out, action.getActionId());
      action.write(out);
    }
  }
  // Write the job ids of the jobs that were recovered
  out.writeInt(recoveredJobs.size());
  for (JobID id : recoveredJobs) {
    id.write(out);
  }
}
 
Example 3
Source File: StorageSerialization.java    From PalDB with Apache License 2.0 6 votes vote down vote up
private static void serializeShort(final DataOutput out, final short val)
    throws IOException {
  if (val == -1) {
    out.write(SHORT_MINUS_1);
  } else if (val == 0) {
    out.write(SHORT_0);
  } else if (val == 1) {
    out.write(SHORT_1);
  } else if (val > 0 && val < 255) {
    out.write(SHORT_255);
    out.write(val);
  } else {
    out.write(SHORT_FULL);
    out.writeShort(val);
  }
}
 
Example 4
Source File: CastToDateOperation.java    From vxquery with Apache License 2.0 5 votes vote down vote up
@Override
public void convertDatetime(XSDateTimePointable datetimep, DataOutput dOut) throws SystemException, IOException {
    dOut.write(ValueTag.XS_DATE_TAG);
    dOut.writeShort((short) datetimep.getYear());
    dOut.write((byte) datetimep.getMonth());
    dOut.write((byte) datetimep.getDay());
    dOut.write((byte) datetimep.getTimezoneHour());
    dOut.write((byte) datetimep.getTimezoneMinute());
}
 
Example 5
Source File: CastToShortOperation.java    From vxquery with Apache License 2.0 5 votes vote down vote up
@Override
public void convertString(UTF8StringPointable stringp, DataOutput dOut) throws SystemException, IOException {
    ICharacterIterator charIterator = new UTF8StringCharacterIterator(stringp);
    charIterator.reset();
    long value = 0;
    int c = 0;
    boolean negative = false;
    long limit = -Short.MAX_VALUE;

    // Check the first character.
    c = charIterator.next();
    if (c == Character.valueOf('-') && negativeAllowed) {
        negative = true;
        c = charIterator.next();
        limit = Short.MIN_VALUE;
    }

    // Read the numeric value.
    do {
        if (Character.isDigit(c)) {
            if (value < limit + Character.getNumericValue(c)) {
                throw new SystemException(ErrorCode.FORG0001);
            }
            value = value * 10 - Character.getNumericValue(c);
        } else {
            throw new SystemException(ErrorCode.FORG0001);
        }
    } while ((c = charIterator.next()) != ICharacterIterator.EOS_CHAR);

    dOut.write(returnTag);
    dOut.writeShort((short) (negative ? value : -value));
}
 
Example 6
Source File: StorageSerialization.java    From PalDB with Apache License 2.0 5 votes vote down vote up
private static void serializeShortArray(final DataOutput out, final short[] val, boolean compress)
    throws IOException {
  if (compress && val.length > 250) {
    out.write(SHORT_ARRAY_C);
    byte[] b = Snappy.compress(val);
    LongPacker.packInt(out, b.length);
    out.write(b);
  } else {
    out.write(SHORT_ARRAY);
    LongPacker.packInt(out, val.length);
    for (short s : val) {
      out.writeShort(s);
    }
  }
}
 
Example 7
Source File: FSImageSerialization.java    From big-c with Apache License 2.0 5 votes vote down vote up
/** Serialize an {@link INodeFileAttributes}. */
public static void writeINodeFileAttributes(INodeFileAttributes file,
    DataOutput out) throws IOException {
  writeLocalName(file, out);
  writePermissionStatus(file, out);
  out.writeLong(file.getModificationTime());
  out.writeLong(file.getAccessTime());

  out.writeShort(file.getFileReplication());
  out.writeLong(file.getPreferredBlockSize());
}
 
Example 8
Source File: DistributedCacheOperation.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void toData(DataOutput out) throws IOException {
  super.toData(out);
  // extra short added for 7.5
  Version version = InternalDataSerializer
          .getVersionForDataStreamOrNull(out);
  if (version == null || Version.GFE_75.compareTo(version) <= 0) {
    short extBits = computeCompressedExtBits((short) 0);
    out.writeShort(extBits);
  }
  DataSerializer.writeString(this.regionPath, out);
  out.writeByte(this.op.ordinal);
  if (this.callbackArg != null) {
    DataSerializer.writeObject(this.callbackArg, out);
  }
  if (this.hasOldValue) {
    out.writeByte(this.oldValueIsObject);
    final byte policy = valueIsToDeserializationPolicy(this.oldValueIsObject);
    final Object vObj;
    final byte[] vBytes;
    if (this.oldValueIsObject == VALUE_IS_BYTES && this.oldValue instanceof byte[]) {
      vObj = null;
      vBytes = (byte[])this.oldValue;
    } else {
      vObj = this.oldValue;
      vBytes = null;
    }
    writeValue(policy, vObj, vBytes, out);
  }
  if (this.filterRouting != null) {
    InternalDataSerializer.invokeToData(this.filterRouting, out);
  }
  if (this.versionTag != null) {
    InternalDataSerializer.invokeToData(this.versionTag,out);
  }
}
 
Example 9
Source File: DataSerializer.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Writes an instance of <code>Short</code> to a
 * <code>DataOutput</code>.
 *
 * @throws IOException
 *         A problem occurs while writing to <code>out</code>
 * @throws NullPointerException if value is null.
 *
 * @see #readShort
 */
public static void writeShort(Short value, DataOutput out)
  throws IOException {

  InternalDataSerializer.checkOut(out);

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

  out.writeShort(value.shortValue());
}
 
Example 10
Source File: GossipData.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void toDataPre_GFE_7_5_0_0(DataOutput out) throws IOException {
  out.writeInt(type);
  if (type == GEMFIRE_VERSION) {
    out.writeShort(versionOrdinal);
  } else {
    out.writeUTF(group == null ? "" : group);
    JChannel.getGfFunctions().writeObject(mbr, out);
    JChannel.getGfFunctions().writeObject(mbrs, out);
    //DataSerializer.writeObject(this.locators, out);
    out.writeBoolean(hasDistributedSystem);
    out.writeBoolean(this.floatingCoordinatorDisabled);
    out.writeBoolean(this.networkPartitionDetectionEnabled);
  }
}
 
Example 11
Source File: FormatIdUtil.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public static void writeFormatIdInteger(DataOutput out, int formatId) throws IOException {
	out.writeShort(formatId);
}
 
Example 12
Source File: jKali_0040_t.java    From coming with MIT License 4 votes vote down vote up
public void writeTo(DataOutput out) throws IOException {
    int size = iTransitions.length;

    // Create unique string pool.
    Set<String> poolSet = new HashSet<String>();
    for (int i=0; i<size; i++) {
        poolSet.add(iNameKeys[i]);
    }

    int poolSize = poolSet.size();
    if (poolSize > 65535) {
        throw new UnsupportedOperationException("String pool is too large");
    }
    String[] pool = new String[poolSize];
    Iterator<String> it = poolSet.iterator();
    for (int i=0; it.hasNext(); i++) {
        pool[i] = it.next();
    }

    // Write out the pool.
    out.writeShort(poolSize);
    for (int i=0; i<poolSize; i++) {
        out.writeUTF(pool[i]);
    }

    out.writeInt(size);

    for (int i=0; i<size; i++) {
        writeMillis(out, iTransitions[i]);
        writeMillis(out, iWallOffsets[i]);
        writeMillis(out, iStandardOffsets[i]);
        
        // Find pool index and write it out.
        String nameKey = iNameKeys[i];
        for (int j=0; j<poolSize; j++) {
            if (pool[j].equals(nameKey)) {
                if (poolSize < 256) {
                    out.writeByte(j);
                } else {
                    out.writeShort(j);
                }
                break;
            }
        }
    }

    out.writeBoolean(iTailZone != null);
    if (iTailZone != null) {
        iTailZone.writeTo(out);
    }
}
 
Example 13
Source File: Elixir_0038_t.java    From coming with MIT License 4 votes vote down vote up
public void writeTo(DataOutput out) throws IOException {
    int size = iTransitions.length;

    // Create unique string pool.
    Set<String> poolSet = new HashSet<String>();
    for (int i=0; i<size; i++) {
        poolSet.add(iNameKeys[i]);
    }

    int poolSize = poolSet.size();
    if (poolSize > 65535) {
        throw new UnsupportedOperationException("String pool is too large");
    }
    String[] pool = new String[poolSize];
    Iterator<String> it = poolSet.iterator();
    for (int i=0; it.hasNext(); i++) {
        pool[i] = it.next();
    }

    // Write out the pool.
    out.writeShort(poolSize);
    for (int i=0; i<poolSize; i++) {
        out.writeUTF(pool[i]);
    }

    out.writeInt(size);

    for (int i=0; i<size; i++) {
        writeMillis(out, iTransitions[i]);
        writeMillis(out, iWallOffsets[i]);
        writeMillis(out, iStandardOffsets[i]);
        
        // Find pool index and write it out.
        String nameKey = iNameKeys[i];
        for (int j=0; j<poolSize; j++) {
            if (pool[j].equals(nameKey)) {
                if (poolSize < 256) {
                    out.writeByte(j);
                } else {
                    out.writeShort(j);
                }
                break;
            }
        }
    }

    out.writeBoolean(iTailZone != null);
    if (iTailZone != null) {
        iTailZone.writeTo(out);
    }
}
 
Example 14
Source File: jKali_0051_t.java    From coming with MIT License 4 votes vote down vote up
public void writeTo(DataOutput out) throws IOException {
    int size = iTransitions.length;

    // Create unique string pool.
    Set<String> poolSet = new HashSet<String>();
    for (int i=0; i<size; i++) {
        poolSet.add(iNameKeys[i]);
    }

    int poolSize = poolSet.size();
    if (poolSize > 65535) {
        throw new UnsupportedOperationException("String pool is too large");
    }
    String[] pool = new String[poolSize];
    Iterator<String> it = poolSet.iterator();
    for (int i=0; it.hasNext(); i++) {
        pool[i] = it.next();
    }

    // Write out the pool.
    out.writeShort(poolSize);
    for (int i=0; i<poolSize; i++) {
        out.writeUTF(pool[i]);
    }

    out.writeInt(size);

    for (int i=0; i<size; i++) {
        writeMillis(out, iTransitions[i]);
        writeMillis(out, iWallOffsets[i]);
        writeMillis(out, iStandardOffsets[i]);
        
        // Find pool index and write it out.
        String nameKey = iNameKeys[i];
        for (int j=0; j<poolSize; j++) {
            if (pool[j].equals(nameKey)) {
                if (poolSize < 256) {
                    out.writeByte(j);
                } else {
                    out.writeShort(j);
                }
                break;
            }
        }
    }

    out.writeBoolean(iTailZone != null);
    if (iTailZone != null) {
        iTailZone.writeTo(out);
    }
}
 
Example 15
Source File: FormatIdUtil.java    From spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
public static void writeFormatIdInteger(DataOutput out, int formatId) throws IOException {
	out.writeShort(formatId);
}
 
Example 16
Source File: CastToGYearOperation.java    From vxquery with Apache License 2.0 4 votes vote down vote up
@Override
public void convertString(UTF8StringPointable stringp, DataOutput dOut) throws SystemException, IOException {
    ICharacterIterator charIterator = new UTF8StringCharacterIterator(stringp);
    charIterator.reset();
    int c;
    int index = 0;
    long[] date = new long[3];
    boolean positiveTimezone = false;
    boolean negativeYear = false;

    // Set defaults
    date[1] = DateTime.TIMEZONE_HOUR_NULL;
    date[2] = DateTime.TIMEZONE_MINUTE_NULL;

    while ((c = charIterator.next()) != ICharacterIterator.EOS_CHAR) {
        if (Character.isDigit(c)) {
            // Add the digit to the current numbered index.
            date[index] = date[index] * 10 + Character.getNumericValue(c);
        } else if (c == Character.valueOf('-') && index == 0 && date[index] == 0) {
            // If the first dash does not have a number in front, its a negative year.
            negativeYear = true;
        } else if (c == Character.valueOf('-') || c == Character.valueOf(':')) {
            // The basic case for going to the next number in the series.
            ++index;
            date[index] = 0;
        } else if (c == Character.valueOf('+')) {
            // Moving to the next number and logging this is now a positive timezone offset.
            ++index;
            date[index] = 0;
            positiveTimezone = true;
        } else if (c == Character.valueOf('Z')) {
            // Set the timezone to UTC.
            date[1] = 0;
            date[2] = 0;
        } else {
            // Invalid date format.
            throw new SystemException(ErrorCode.FORG0001);
        }
    }
    // Final touches on year and timezone.
    if (negativeYear) {
        date[0] *= -1;
    }
    if (!positiveTimezone && date[1] != DateTime.TIMEZONE_HOUR_NULL) {
        date[1] *= -1;
    }
    if (!positiveTimezone && date[2] != DateTime.TIMEZONE_MINUTE_NULL) {
        date[2] *= -1;
    }
    if (!DateTime.valid(date[0], 1, 1, 0, 0, 0, date[1], date[2])) {
        throw new SystemException(ErrorCode.FODT0001);
    }

    dOut.write(ValueTag.XS_G_YEAR_TAG);
    dOut.writeShort((short) date[0]);
    dOut.write((byte) 1);
    dOut.write((byte) 1);
    dOut.write((byte) date[1]);
    dOut.write((byte) date[2]);
}
 
Example 17
Source File: LongWritable.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
@Override
public void writeType(DataOutput out) throws IOException {
    out.writeShort(WritableType.Long.typeIdx());
}
 
Example 18
Source File: Arja_00110_s.java    From coming with MIT License 4 votes vote down vote up
public void writeTo(DataOutput out) throws IOException {
    int size = iTransitions.length;

    // Create unique string pool.
    Set<String> poolSet = new HashSet<String>();
    for (int i=0; i<size; i++) {
        poolSet.add(iNameKeys[i]);
    }

    int poolSize = poolSet.size();
    if (poolSize > 65535) {
        throw new UnsupportedOperationException("String pool is too large");
    }
    String[] pool = new String[poolSize];
    Iterator<String> it = poolSet.iterator();
    for (int i=0; it.hasNext(); i++) {
        pool[i] = it.next();
    }

    // Write out the pool.
    out.writeShort(poolSize);
    for (int i=0; i<poolSize; i++) {
        out.writeUTF(pool[i]);
    }

    out.writeInt(size);

    for (int i=0; i<size; i++) {
        writeMillis(out, iTransitions[i]);
        writeMillis(out, iWallOffsets[i]);
        writeMillis(out, iStandardOffsets[i]);
        
        // Find pool index and write it out.
        String nameKey = iNameKeys[i];
        for (int j=0; j<poolSize; j++) {
            if (pool[j].equals(nameKey)) {
                if (poolSize < 256) {
                    out.writeByte(j);
                } else {
                    out.writeShort(j);
                }
                break;
            }
        }
    }

    out.writeBoolean(iTailZone != null);
    if (iTailZone != null) {
        iTailZone.writeTo(out);
    }
}
 
Example 19
Source File: ImageWritable.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
@Override
public void writeType(DataOutput out) throws IOException {
    out.writeShort(WritableType.Image.typeIdx());
}
 
Example 20
Source File: UID.java    From JDKSourceCode1.8 with MIT License 2 votes vote down vote up
/**
 * Marshals a binary representation of this <code>UID</code> to
 * a <code>DataOutput</code> instance.
 *
 * <p>Specifically, this method first invokes the given stream's
 * {@link DataOutput#writeInt(int)} method with this <code>UID</code>'s
 * <code>unique</code> value, then it invokes the stream's
 * {@link DataOutput#writeLong(long)} method with this <code>UID</code>'s
 * <code>time</code> value, and then it invokes the stream's
 * {@link DataOutput#writeShort(int)} method with this <code>UID</code>'s
 * <code>count</code> value.
 *
 * @param   out the <code>DataOutput</code> instance to write
 * this <code>UID</code> to
 *
 * @throws  IOException if an I/O error occurs while performing
 * this operation
 */
public void write(DataOutput out) throws IOException {
    out.writeInt(unique);
    out.writeLong(time);
    out.writeShort(count);
}