下面列出了java.io.DataOutput#writeLong ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/** {@inheritDoc} */
public void write(DataOutput out) throws IOException {
super.write(out);
//TODO: move it to DatanodeID once DatanodeID is not stored in FSImage
out.writeShort(ipcPort);
out.writeLong(capacity);
out.writeLong(dfsUsed);
out.writeLong(remaining);
out.writeLong(lastUpdate);
out.writeInt(xceiverCount);
Text.writeString(out, location);
Text.writeString(out, hostName == null? "": hostName);
WritableUtils.writeEnum(out, getAdminState());
}
@Nonnull
private static ThrowableComputable<PersistentHashMap<String, Record>, IOException> getComputable(final File file) {
return () -> new PersistentHashMap<>(file, EnumeratorStringDescriptor.INSTANCE, new DataExternalizer<Record>() {
@Override
public void save(@Nonnull DataOutput out, Record value) throws IOException {
out.writeInt(value.magnitude);
out.writeLong(value.date.getTime());
out.writeLong(value.configurationHash);
}
@Override
public Record read(@Nonnull DataInput in) throws IOException {
return new Record(in.readInt(), new Date(in.readLong()), in.readLong());
}
}, 4096, CURRENT_VERSION);
}
/** 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());
}
@Override
public void writeFields(DataOutput out) throws IOException {
out.writeLong(requestId);
out.writeUTF(segment);
out.writeUTF(delegationToken == null ? "" : delegationToken);
out.writeInt(suggestedEntryCount);
out.writeInt(continuationToken.readableBytes()); // continuation token length.
if (continuationToken.readableBytes() != 0) {
continuationToken.getBytes(continuationToken.readerIndex(), (OutputStream) out, continuationToken.readableBytes());
}
}
public void toData(DataOutput out)
throws IOException {
out.writeInt(this.acctId);
DataSerializer.writeString(this.customerName, out);
out.writeDouble(this.netWorth);
DataSerializer.writeHashMap((HashMap)this.assets, out);
out.writeLong(this.timestamp);
if (fineEnabled) {
Log.getLogWriter().fine("INVOKED: toData on key " + this.acctId);
}
}
/**
* 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);
}
@Override
public void writeFields(DataOutput out) throws IOException {
out.writeLong(writerId.getMostSignificantBits());
out.writeLong(writerId.getLeastSignificantBits());
out.writeLong(eventNumber);
out.writeLong(expectedOffset);
event.writeFields(out);
}
void write( DataOutput out ) throws IOException
{
out.writeInt( status );
out.writeLong( length );
out.writeInt( blockCount );
for ( int i = 0; i < DIRECT_BLOCK_COUNT; i++ )
{
out.writeInt( directBlocks[i] );
}
for ( int i = 0; i < INDIRECT_BLOCK_COUNT; i++ )
{
out.writeInt( indirectBlocks[i] );
}
}
@Override
public void toData(DataOutput out)
throws IOException {
super.toData(out);
if (GemFireXDUtils.TraceApplicationJars) {
SanityManager.DEBUG_PRINT(GfxdConstants.TRACE_APP_JARS,
"GfxdJarMessage#toData: this.sendBytes " + this.sendBytes
+ " and jar bytes " + Arrays.toString(this.jar_bytes));
}
out.writeLong(this.id);
DataSerializer.writeString(this.schemaName, out);
DataSerializer.writeString(this.sqlName, out);
DataSerializer.writeByte((byte)this.type, out);
if (this.type != JAR_REMOVE) {
if (this.sendBytes) {
if (GemFireXDUtils.TraceApplicationJars) {
SanityManager.DEBUG_PRINT(GfxdConstants.TRACE_APP_JARS,
"GfxdJarMessage#toData: writing byte array "
+ Arrays.toString(this.jar_bytes));
}
DataSerializer.writeByteArray(this.jar_bytes, out);
}
else {
if (GemFireXDUtils.TraceApplicationJars) {
SanityManager.DEBUG_PRINT(GfxdConstants.TRACE_APP_JARS,
"GfxdJarMessage#toData: sending null jar bytes "
+ Arrays.toString(this.jar_bytes));
}
DataSerializer.writeByteArray(null, out);
}
DataSerializer.writeLong(this.oldId, out);
}
}
@Override
public void toData(final DataOutput out) throws IOException {
super.toData(out);
DataSerializer.writePrimitiveByte(this.flags, out);
out.writeLong(this.connId);
out.writeLong(this.id);
InternalDataSerializer.invokeToData(this.ddl, out);
}
/**
* Writes the state to the stream.
*
* @param epochSec the epoch seconds, not null
* @param out the output stream, not null
* @throws IOException if an error occurs
*/
static void writeEpochSec(long epochSec, DataOutput out) throws IOException {
if (epochSec >= -4575744000L && epochSec < 10413792000L && epochSec % 900 == 0) { // quarter hours between 1825 and 2300
int store = (int) ((epochSec + 4575744000L) / 900);
out.writeByte((store >>> 16) & 255);
out.writeByte((store >>> 8) & 255);
out.writeByte(store & 255);
} else {
out.writeByte(255);
out.writeLong(epochSec);
}
}
@Override
public void write(DataOutput out) throws IOException {
super.write(out);
int sizeInWords = buckets2words(vectorSize);
for(int i = 0; i < sizeInWords; i++) {
out.writeLong(buckets[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);
}
void writeExternal(DataOutput out) throws IOException {
out.writeLong(seconds);
out.writeInt(nanos);
}
@Override
public void encode(DataOutput out, TrackExceptionMessage message) throws IOException {
out.writeLong(message.executorId);
ExceptionTools.encodeException(out, message.exception);
}
@Override
public void writeFields(DataOutput out) throws IOException {
out.writeLong(writerId.getMostSignificantBits());
out.writeLong(writerId.getLeastSignificantBits());
out.writeLong(eventNumber);
}
public void write(DataOutput dataOutput, LockInfo lockInfo) throws IOException {
dataOutput.writeInt(lockInfo.port);
dataOutput.writeLong(lockInfo.lockId);
dataOutput.writeUTF(trimIfNecessary(lockInfo.pid));
dataOutput.writeUTF(trimIfNecessary(lockInfo.operation));
}
public void writeToObjectStream(DataOutput dataOut) throws java.io.IOException
{
dataOut.writeUTF(name == null ? "" : name);
dataOut.writeUTF(id == null ? "" : id);
dataOut.writeUTF(desc == null ? "" : desc);
dataOut.writeUTF(type == null ? "" : type);
dataOut.writeInt(screenshotURLs == null ? 0 : screenshotURLs.size());
for (int i = 0; screenshotURLs != null && i < screenshotURLs.size(); i++)
dataOut.writeUTF(screenshotURLs.get(i).toString());
dataOut.writeInt(demoVideoURLs == null ? 0 : demoVideoURLs.size());
for (int i = 0; demoVideoURLs != null && i < demoVideoURLs.size(); i++)
dataOut.writeUTF(demoVideoURLs.get(i).toString());
dataOut.writeUTF(author == null ? "" : author);
dataOut.writeLong(createDate);
dataOut.writeLong(modDate);
dataOut.writeLong(installDate);
dataOut.writeUTF(version == null ? "" : version);
dataOut.writeUTF(resPath == null ? "" : resPath);
dataOut.writeInt(webpages == null ? 0 : webpages.size());
for (int i = 0; webpages != null && i < webpages.size(); i++)
dataOut.writeUTF(webpages.get(i).toString());
dataOut.writeUTF(implClass == null ? "" : implClass);
dataOut.writeBoolean(desktopOnly);
dataOut.writeBoolean(serverOnly);
dataOut.writeBoolean(winOK);
dataOut.writeBoolean(linuxOK);
dataOut.writeBoolean(macOK);
dataOut.writeInt(dependencies == null ? 0 : dependencies.size());
for (int i = 0; dependencies != null && i < dependencies.size(); i++)
{
Dependency dep = (Dependency) dependencies.get(i);
dataOut.writeUTF(dep.id == null ? "" : dep.id);
dataOut.writeUTF(dep.minVersion == null ? "" : dep.minVersion);
dataOut.writeUTF(dep.maxVersion == null ? "" : dep.maxVersion);
dataOut.writeUTF(dep.type == null ? "" : dep.type);
}
dataOut.writeInt(packages == null ? 0 : packages.size());
for (int i = 0; packages != null && i < packages.size(); i++)
{
Package pack = (Package) packages.get(i);
dataOut.writeUTF(pack.type == null ? "" : pack.type);
dataOut.writeUTF(pack.url == null ? "" : pack.url);
dataOut.writeUTF(pack.rawMD5 == null ? "" : pack.rawMD5);
dataOut.writeBoolean(pack.overwrite);
}
dataOut.writeInt(state);
dataOut.writeInt(installIndex);
dataOut.writeInt(stvImports == null ? 0 : stvImports.size());
for (int i = 0; stvImports != null && i < stvImports.size(); i++)
dataOut.writeUTF(stvImports.get(i).toString());
dataOut.writeBoolean(beta);
dataOut.writeUTF(releaseNotes == null ? "" : releaseNotes);
}
@Override
public void toData(DataOutput out) throws IOException {
out.writeLong(f1);
out.writeUTF(f2);
}
@Override
public void writeFields(DataOutput out) throws IOException {
out.writeLong(requestId);
out.writeUTF(segment);
out.writeUTF(serverStackTrace);
}