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

The following examples show how to use java.io.DataOutput#writeByte() . 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: RegionInfoShip.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * @see DataSerializable#toData(DataOutput)
 */
public void toData(DataOutput out) throws IOException {
  out.writeByte(this.type);
  switch (this.type) {
    case IS_BUC:
      InternalDataSerializer.writeUnsignedVL(this.prId, out);
      InternalDataSerializer.writeSignedVL(this.bucketId, out);
      break;
    case IS_RR:
      DataSerializer.writeString(this.fullPath, out);
      break;
    case IS_PR:
      InternalDataSerializer.writeUnsignedVL(this.prId, out);
      break;
    default:
      throw new InternalGemFireError(
          "RegionInfoShip#toData: unknown type of region: " + this.type);
  }
}
 
Example 2
Source File: Ser.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private static void writeInternal(byte type, Object object, DataOutput out) throws IOException {
    out.writeByte(type);
    switch (type) {
        case ZRULES:
            ((ZoneRules) object).writeExternal(out);
            break;
        case ZOT:
            ((ZoneOffsetTransition) object).writeExternal(out);
            break;
        case ZOTRULE:
            ((ZoneOffsetTransitionRule) object).writeExternal(out);
            break;
        default:
            throw new InvalidClassException("Unknown serialized type");
    }
}
 
Example 3
Source File: MithraTimestamp.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public static void writeTimezoneInsensitiveTimestampWithInfinity(DataOutput out,
        long timestamp, Timestamp infinity) throws IOException
{
    if (timestamp == TimestampPool.OFF_HEAP_NULL)
    {
        out.writeByte(IS_NULL);
        return;
    }
    if (timestamp == infinity.getTime())
    {
        out.writeByte(IS_INFINITY);
        return;
    }
    // we'll write the time in UTC
    timestamp += getDefaultOffset(timestamp);

    writeNormalTimestamp(out, timestamp, 0);
}
 
Example 4
Source File: LocalTime.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
void writeExternal(DataOutput out) throws IOException {
    if (nano == 0) {
        if (second == 0) {
            if (minute == 0) {
                out.writeByte(~hour);
            } else {
                out.writeByte(hour);
                out.writeByte(~minute);
            }
        } else {
            out.writeByte(hour);
            out.writeByte(minute);
            out.writeByte(~second);
        }
    } else {
        out.writeByte(hour);
        out.writeByte(minute);
        out.writeByte(second);
        out.writeInt(nano);
    }
}
 
Example 5
Source File: PartitionedBlock.java    From systemds with Apache License 2.0 5 votes vote down vote up
private void writeHeaderAndPayload(DataOutput dos) 
	throws IOException
{
	dos.writeInt(_dims.length);
	for (long dim : _dims)
		dos.writeLong(dim);
	dos.writeInt(_blen);
	dos.writeInt(_offset);
	dos.writeInt(_partBlocks.length);
	dos.writeByte(CacheBlockFactory.getCode(_partBlocks[0]));
	
	for( CacheBlock block : _partBlocks )
		block.write(dos);
}
 
Example 6
Source File: jKali_0030_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Millisecond encoding formats:
 *
 * upper two bits  units       field length  approximate range
 * ---------------------------------------------------------------
 * 00              30 minutes  1 byte        +/- 16 hours
 * 01              minutes     4 bytes       +/- 1020 years
 * 10              seconds     5 bytes       +/- 4355 years
 * 11              millis      9 bytes       +/- 292,000,000 years
 *
 * Remaining bits in field form signed offset from 1970-01-01T00:00:00Z.
 */
static void writeMillis(DataOutput out, long millis) throws IOException {
    if (millis % (30 * 60000L) == 0) {
        // Try to write in 30 minute units.
        long units = millis / (30 * 60000L);
        if (((units << (64 - 6)) >> (64 - 6)) == units) {
            // Form 00 (6 bits effective precision)
            out.writeByte((int)(units & 0x3f));
            return;
        }
    }

    if (millis % 60000L == 0) {
        // Try to write minutes.
        long minutes = millis / 60000L;
        if (((minutes << (64 - 30)) >> (64 - 30)) == minutes) {
            // Form 01 (30 bits effective precision)
            out.writeInt(0x40000000 | (int)(minutes & 0x3fffffff));
            return;
        }
    }
    
    if (millis % 1000L == 0) {
        // Try to write seconds.
        long seconds = millis / 1000L;
        if (((seconds << (64 - 38)) >> (64 - 38)) == seconds) {
            // Form 10 (38 bits effective precision)
            out.writeByte(0x80 | (int)((seconds >> 32) & 0x3f));
            out.writeInt((int)(seconds & 0xffffffff));
            return;
        }
    }

    // Write milliseconds either because the additional precision is
    // required or the minutes didn't fit in the field.
    
    // Form 11 (64 bits effective precision, but write as if 70 bits)
    out.writeByte(millis < 0 ? 0xff : 0xc0);
    out.writeLong(millis);
}
 
Example 7
Source File: Arja_00146_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Millisecond encoding formats:
 *
 * upper two bits  units       field length  approximate range
 * ---------------------------------------------------------------
 * 00              30 minutes  1 byte        +/- 16 hours
 * 01              minutes     4 bytes       +/- 1020 years
 * 10              seconds     5 bytes       +/- 4355 years
 * 11              millis      9 bytes       +/- 292,000,000 years
 *
 * Remaining bits in field form signed offset from 1970-01-01T00:00:00Z.
 */
static void writeMillis(DataOutput out, long millis) throws IOException {
    if (millis % (30 * 60000L) == 0) {
        // Try to write in 30 minute units.
        long units = millis / (30 * 60000L);
        if (((units << (64 - 6)) >> (64 - 6)) == units) {
            // Form 00 (6 bits effective precision)
            out.writeByte((int)(units & 0x3f));
            return;
        }
    }

    if (millis % 60000L == 0) {
        // Try to write minutes.
        long minutes = millis / 60000L;
        if (((minutes << (64 - 30)) >> (64 - 30)) == minutes) {
            // Form 01 (30 bits effective precision)
            out.writeInt(0x40000000 | (int)(minutes & 0x3fffffff));
            return;
        }
    }
    
    if (millis % 1000L == 0) {
        // Try to write seconds.
        long seconds = millis / 1000L;
        if (((seconds << (64 - 38)) >> (64 - 38)) == seconds) {
            // Form 10 (38 bits effective precision)
            out.writeByte(0x80 | (int)((seconds >> 32) & 0x3f));
            out.writeInt((int)(seconds & 0xffffffff));
            return;
        }
    }

    // Write milliseconds either because the additional precision is
    // required or the minutes didn't fit in the field.
    
    // Form 11 (64 bits effective precision, but write as if 70 bits)
    out.writeByte(millis < 0 ? 0xff : 0xc0);
    out.writeLong(millis);
}
 
Example 8
Source File: PMDMaterial.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void writeToStream(DataOutput os) throws IOException {
    material.writeToStream(os);
    os.writeByte(toonIndex);
    os.writeByte(edgeFlag);
    os.writeInt(faceVertCount);
    PMDUtil.writeString(os, textureFileName, 20);
}
 
Example 9
Source File: ZoneRules.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Writes the state the ZoneOffset to the stream.
 *
 * @param offset  the offset, not null
 * @param out  the output stream, not null
 * @throws IOException if an error occurs
 */
static void writeOffset(ZoneOffset offset, DataOutput out) throws IOException {
    final int offsetSecs = offset.getTotalSeconds();
    int offsetByte = offsetSecs % 900 == 0 ? offsetSecs / 900 : 127;  // compress to -72 to +72
    out.writeByte(offsetByte);
    if (offsetByte == 127) {
        out.writeInt(offsetSecs);
    }
}
 
Example 10
Source File: RemoteInvalidateMessage.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);
  byte b = 0;
  if (this.versionTag != null) {
    b |= HAS_VERSION;
  }
  if (this.versionTag instanceof DiskVersionTag) {
    b |= PERSISTENT;
  }
  out.writeByte(b);
  if (this.versionTag != null) {
    InternalDataSerializer.invokeToData(this.versionTag, out);
  }
}
 
Example 11
Source File: Arja_00129_s.java    From coming with MIT License 5 votes vote down vote up
public void writeTo(DataOutput out) throws IOException {
    out.writeByte(iMode);
    out.writeByte(iMonthOfYear);
    out.writeByte(iDayOfMonth);
    out.writeByte(iDayOfWeek);
    out.writeBoolean(iAdvance);
    writeMillis(out, iMillisOfDay);
}
 
Example 12
Source File: JapaneseDate.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
void writeExternal(DataOutput out) throws IOException {
    // JapaneseChronology is implicit in the JAPANESE_DATE_TYPE
    out.writeInt(get(YEAR));
    out.writeByte(get(MONTH_OF_YEAR));
    out.writeByte(get(DAY_OF_MONTH));
}
 
Example 13
Source File: ZoneRegion.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
void write(DataOutput out) throws IOException {
    out.writeByte(Ser.ZONE_REGION_TYPE);
    writeExternal(out);
}
 
Example 14
Source File: UnityReadCoilsResponse.java    From dn-modbus with Apache License 2.0 4 votes vote down vote up
public void writeData(DataOutput dout) throws IOException {
	dout.writeByte(m_Coils.byteSize());
	dout.write(m_Coils.getBytes(), 0, m_Coils.byteSize());
}
 
Example 15
Source File: LocalDate.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
void writeExternal(DataOutput out) throws IOException {
    out.writeInt(year);
    out.writeByte(month);
    out.writeByte(day);
}
 
Example 16
Source File: JapaneseEra.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
void writeExternal(DataOutput out) throws IOException {
    out.writeByte(this.getValue());
}
 
Example 17
Source File: ByteWritable.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public void write(DataOutput out) throws IOException {
    out.writeByte(value);
}
 
Example 18
Source File: Nopol2017_0085_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 19
Source File: Ser.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
static void writeInternal(byte type, Object object, DataOutput out) throws IOException {
    out.writeByte(type);
    switch (type) {
        case DURATION_TYPE:
            ((Duration) object).writeExternal(out);
            break;
        case INSTANT_TYPE:
            ((Instant) object).writeExternal(out);
            break;
        case LOCAL_DATE_TYPE:
            ((LocalDate) object).writeExternal(out);
            break;
        case LOCAL_DATE_TIME_TYPE:
            ((LocalDateTime) object).writeExternal(out);
            break;
        case LOCAL_TIME_TYPE:
            ((LocalTime) object).writeExternal(out);
            break;
        case MONTH_DAY_TYPE:
            ((MonthDay) object).writeExternal(out);
            break;
        case OFFSET_DATE_TIME_TYPE:
            ((OffsetDateTime) object).writeExternal(out);
            break;
        case OFFSET_TIME_TYPE:
            ((OffsetTime) object).writeExternal(out);
            break;
        case YEAR_MONTH_TYPE:
            ((YearMonth) object).writeExternal(out);
            break;
        case YEAR_TYPE:
            ((Year) object).writeExternal(out);
            break;
        case ZONE_REGION_TYPE:
            ((ZoneRegion) object).writeExternal(out);
            break;
        case ZONE_OFFSET_TYPE:
            ((ZoneOffset) object).writeExternal(out);
            break;
        case ZONED_DATE_TIME_TYPE:
            ((ZonedDateTime) object).writeExternal(out);
            break;
        default:
            throw new InvalidClassException("Unknown serialized type");
    }
}
 
Example 20
Source File: jKali_0051_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);
    }
}