下面列出了java.io.DataOutput#writeInt ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
protected void writePayload(DataOutput output, ByteBuffer header, int options)
throws IOException {
super.writePayload(output, header, options);
output.writeInt(namespace);
output.writeInt(name);
output.writeShort((short) XmlAttribute.SIZE); // attribute start
output.writeShort((short) XmlAttribute.SIZE);
output.writeShort((short) attributes.size());
output.writeShort((short) (idIndex + 1));
output.writeShort((short) (classIndex + 1));
output.writeShort((short) (styleIndex + 1));
for (XmlAttribute attribute : attributes) {
output.write(attribute.toByteArray(options));
}
}
public synchronized void write(DataOutput out) throws IOException {
jobid.write(out);
out.writeFloat(setupProgress);
out.writeFloat(mapProgress);
out.writeFloat(reduceProgress);
out.writeFloat(cleanupProgress);
out.writeInt(runState);
out.writeLong(startTime);
Text.writeString(out, user);
WritableUtils.writeEnum(out, priority);
Text.writeString(out, schedulingInfo);
}
@Override
public void toData(DataOutput out) throws IOException {
super.toData(out);
DataSerializer.writeStringArray(this.groups, out);
out.writeInt(maxConnections);
InternalDataSerializer.invokeToData(initialLoad, out);
out.writeLong(getLoadPollInterval());
}
void write(DataOutput out, int flags) throws IOException
{
super.write(out, flags);
boolean useLookupIdx = (flags & Wizard.WRITE_OPT_USE_ARRAY_INDICES) != 0;
out.writeInt(showID);
out.writeInt((title == null) ? 0 : (useLookupIdx ? title.lookupIdx : title.id));
out.writeInt((network == null) ? 0 : (useLookupIdx ? network.lookupIdx : network.id));
out.writeUTF(airdate);
out.writeUTF(description);
out.writeUTF(imageURL);
}
public void toData(DataOutput out) throws IOException
{
out.writeInt(indexListSize);
out.writeInt(indexMapSize);
out.writeInt(minSetSize);
out.writeInt(maxSetSize);
DataSerializer.writeObject(minSetQueryKey, out);
DataSerializer.writeObject(maxSetQueryKey, out);
}
/**
* Sorts the items in the collection and writes it to the given output stream.
*
* @param itemCollection a collection of items.
* @param dataOutputStream where the items must be written.
* @param dotted whether package names must use dots, instead of slashes.
* @exception IOException if an error occurs.
*/
private static void writeItems(
final Collection<Item> itemCollection,
final DataOutput dataOutputStream,
final boolean dotted)
throws IOException {
Item[] items = itemCollection.toArray(new Item[0]);
Arrays.sort(items);
for (Item item : items) {
dataOutputStream.writeUTF(item.name);
dataOutputStream.writeInt(item.access);
dataOutputStream.writeUTF(dotted ? item.descriptor.replace('/', '.') : item.descriptor);
}
}
private static void writeFiles(DataOutput os, Set<File> files) throws IOException {
if (files == null) {
os.writeInt(0);
return;
}
os.writeInt(files.size());
for (File f : files) {
Stamps.writeRelativePath(f.getPath(), os);
}
}
@Override
public void write(DataOutput out) throws IOException {
// write col contents first (w/ meta data)
_data.write(out);
// write col indices
int len = _data.getNumColumns();
for(int i = 0; i < len; i++)
out.writeInt(_colIndexes[i]);
}
/**
* 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);
}
public void write(DataOutput out) throws IOException {
out.writeInt(this.namespaceid);
out.writeInt(this.methodFingerPrint);
super.write(out);
}
public void toData(DataOutput out) throws IOException {
out.writeInt(this.maximum);
DataSerializer.writeObject(this.action, out);
DataSerializer.writeObject(this.algorithm, out);
}
@Override
public void write(DataOutput output) throws IOException {
output.writeInt(binary.length());
binary.writeTo(output);
}
/**
* Writes the state of the transition rule to the stream.
*
* @param rule the transition rule, not null
* @param out the output stream, not null
* @throws IOException if an error occurs
*/
static void writeRule(ZoneOffsetTransitionRule rule, DataOutput out) throws IOException {
int month = rule.month;
byte dom = rule.dom;
int dow = rule.dow;
LocalTime time = rule.time;
boolean timeEndOfDay = rule.timeEndOfDay;
TimeDefinition timeDefinition = rule.timeDefinition;
ZoneOffset standardOffset = rule.standardOffset;
ZoneOffset offsetBefore = rule.offsetBefore;
ZoneOffset offsetAfter = rule.offsetAfter;
int timeSecs = (timeEndOfDay ? 86400 : time.toSecondOfDay());
int stdOffset = standardOffset.getTotalSeconds();
int beforeDiff = offsetBefore.getTotalSeconds() - stdOffset;
int afterDiff = offsetAfter.getTotalSeconds() - stdOffset;
int timeByte = (timeSecs % 3600 == 0 ? (timeEndOfDay ? 24 : time.getHour()) : 31);
int stdOffsetByte = (stdOffset % 900 == 0 ? stdOffset / 900 + 128 : 255);
int beforeByte = (beforeDiff == 0 || beforeDiff == 1800 || beforeDiff == 3600 ? beforeDiff / 1800 : 3);
int afterByte = (afterDiff == 0 || afterDiff == 1800 || afterDiff == 3600 ? afterDiff / 1800 : 3);
int dowByte = (dow == -1 ? 0 : dow);
int b = (month << 28) + // 4 bytes
((dom + 32) << 22) + // 6 bytes
(dowByte << 19) + // 3 bytes
(timeByte << 14) + // 5 bytes
(timeDefinition.ordinal() << 12) + // 2 bytes
(stdOffsetByte << 4) + // 8 bytes
(beforeByte << 2) + // 2 bytes
afterByte; // 2 bytes
out.writeInt(b);
if (timeByte == 31) {
out.writeInt(timeSecs);
}
if (stdOffsetByte == 255) {
out.writeInt(stdOffset);
}
if (beforeByte == 3) {
out.writeInt(offsetBefore.getTotalSeconds());
}
if (afterByte == 3) {
out.writeInt(offsetAfter.getTotalSeconds());
}
}
void writeExternal(DataOutput out) throws IOException {
out.writeInt(years);
out.writeInt(months);
out.writeInt(days);
}
void writeExternal(DataOutput out) throws IOException {
out.writeInt(years);
out.writeInt(months);
out.writeInt(days);
}
public void serialize(BloomFilter bf, DataOutput out) throws IOException {
out.writeInt(bf.hashCount);
bf.bitset.serialize(out);
}
@Override
public void write(DataOutput out) throws IOException {
out.writeInt(identifier);
}
public void toData(DataOutput out) throws IOException {
out.writeInt(this.field1);
}
public void write(DataOutput out) throws IOException {
out.writeInt(value);
}
public void toData(DataOutput out) throws IOException {
DataSerializer.writeProperties(this.resolveProps, out);
out.writeInt(this.numBuckets);
}