本文整理匯總了Java中java.io.DataOutput類的典型用法代碼示例。如果您正苦於以下問題:Java DataOutput類的具體用法?Java DataOutput怎麽用?Java DataOutput使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DataOutput類屬於java.io包,在下文中一共展示了DataOutput類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: write
import java.io.DataOutput; //導入依賴的package包/類
/**
* Write the actual data contents of the tag, implemented in NBT extension classes
*/
void write(DataOutput output) throws IOException
{
if (!this.tagList.isEmpty())
{
this.tagType = ((NBTBase)this.tagList.get(0)).getId();
}
else
{
this.tagType = 0;
}
output.writeByte(this.tagType);
output.writeInt(this.tagList.size());
for (int i = 0; i < this.tagList.size(); ++i)
{
((NBTBase)this.tagList.get(i)).write(output);
}
}
示例2: write
import java.io.DataOutput; //導入依賴的package包/類
/**
* FileSystemGroup ::= #scheme (scheme #counter (key value)*)*
*/
@Override
public void write(DataOutput out) throws IOException {
WritableUtils.writeVInt(out, map.size()); // #scheme
for (Map.Entry<String, Object[]> entry : map.entrySet()) {
WritableUtils.writeString(out, entry.getKey()); // scheme
// #counter for the above scheme
WritableUtils.writeVInt(out, numSetCounters(entry.getValue()));
for (Object counter : entry.getValue()) {
if (counter == null) continue;
@SuppressWarnings("unchecked")
FSCounter c = (FSCounter) ((Counter)counter).getUnderlyingCounter();
WritableUtils.writeVInt(out, c.key.ordinal()); // key
WritableUtils.writeVLong(out, c.getValue()); // value
}
}
}
示例3: write
import java.io.DataOutput; //導入依賴的package包/類
@Override
public void write(DataOutput out) throws IOException {
super.write(out);
WritableUtils.writeVInt(out, id);
WritableUtils.writeVInt(out, maps);
WritableUtils.writeVLong(out, inputRecords);
WritableUtils.writeVLong(out, outputBytes);
WritableUtils.writeVLong(out, outputRecords);
WritableUtils.writeVLong(out, maxMemory);
WritableUtils.writeVInt(out, reduces);
for (int i = 0; i < reduces; ++i) {
out.writeDouble(reduceBytes[i]);
out.writeDouble(reduceRecords[i]);
}
WritableUtils.writeVInt(out, nSpec);
for (int i = 0; i < nSpec; ++i) {
WritableUtils.writeVLong(out, reduceOutputBytes[i]);
WritableUtils.writeVLong(out, reduceOutputRecords[i]);
}
}
示例4: produceRelativePath
import java.io.DataOutput; //導入依賴的package包/類
private static void produceRelativePath(String path, Object out) throws IOException {
if (path.isEmpty()) {
if (out instanceof DataOutput) {
DataOutput dos = (DataOutput)out;
dos.writeUTF(path);
}
return;
}
if (testWritePath(path, System.getProperty("netbeans.user"), "user", out)) { // NOI18N
return;
}
int cnt = 0;
for (String p : Clusters.dirs()) {
if (testWritePath(path, p, "" + cnt, out)) {
return;
}
cnt++;
}
if (testWritePath(path, System.getProperty("netbeans.home"), "home", out)) { // NOI18N
return;
}
LOG.log(Level.FINE, "Cannot find relative path for {0}", path); // NOI18N
doWritePath("abs", path, out); // NOI18N
}
示例5: writeStringArray
import java.io.DataOutput; //導入依賴的package包/類
/**
* Writes an array of <code>String</code>s to a <code>DataOutput</code>. This method will
* serialize a <code>null</code> array and not throw a <code>NullPointerException</code>.
*
* @throws IOException A problem occurs while writing to <code>out</code>
*
* @see #readStringArray
* @see #writeString
*/
public static void writeStringArray(String[] array, DataOutput out) throws IOException {
InternalDataSerializer.checkOut(out);
int length;
if (array == null) {
length = -1;
} else {
length = array.length;
}
InternalDataSerializer.writeArrayLength(length, out);
if (logger.isTraceEnabled(LogMarker.SERIALIZER)) {
logger.trace(LogMarker.SERIALIZER, "Writing String array of length {}", length);
}
if (length > 0) {
for (int i = 0; i < length; i++) {
writeString(array[i], out);
}
}
}
示例6: readWrite
import java.io.DataOutput; //導入依賴的package包/類
private int readWrite(ProgressWindow progress, DataOutput out, int size, byte[] buffer) {
if (size == 0)
return 0;
try {
in.readFully(buffer, 0, size);
if (size != BUFFERSIZE)
progress.setText("Finishing up the transfer..");
out.write(buffer, 0, size);
} catch (Exception ex) {
progress.setText("Transmission error!");
System.out.println("Transmission error");
return -1;
}
bytesSent += size;
progress.setText("Transfered: " + Util.getStringFromBytes(bytesSent),
FileProgressWindow.BAR_1);
progress.setValue(bytesSent + amountToSkip, FileProgressWindow.BAR_1);
return size;
}
示例7: writeStrings
import java.io.DataOutput; //導入依賴的package包/類
private int writeStrings(DataOutput payload, ByteBuffer offsets, boolean shrink) throws IOException {
int stringOffset = 0;
Map<String, Integer> used = new HashMap<>(); // Keeps track of strings already written
for (String string : strings) {
// Dedupe everything except stylized strings, unless shrink is true (then dedupe everything)
if (used.containsKey(string) && (shrink || isOriginalDeduped)) {
Integer offset = used.get(string);
offsets.putInt(offset == null ? 0 : offset);
} else {
byte[] encodedString = ResourceString.encodeString(string, getStringType());
payload.write(encodedString);
used.put(string, stringOffset);
offsets.putInt(stringOffset);
stringOffset += encodedString.length;
}
}
// ARSC files pad to a 4-byte boundary. We should do so too.
stringOffset = writePad(payload, stringOffset);
return stringOffset;
}
示例8: saveINodeDiffs
import java.io.DataOutput; //導入依賴的package包/類
/**
* Save SnapshotDiff list for an INodeDirectoryWithSnapshot.
* @param sNode The directory that the SnapshotDiff list belongs to.
* @param out The {@link DataOutput} to write.
*/
private static <N extends INode, A extends INodeAttributes, D extends AbstractINodeDiff<N, A, D>>
void saveINodeDiffs(final AbstractINodeDiffList<N, A, D> diffs,
final DataOutput out, ReferenceMap referenceMap) throws IOException {
// Record the diffs in reversed order, so that we can find the correct
// reference for INodes in the created list when loading the FSImage
if (diffs == null) {
out.writeInt(-1); // no diffs
} else {
final List<D> list = diffs.asList();
final int size = list.size();
out.writeInt(size);
for (int i = size - 1; i >= 0; i--) {
list.get(i).write(out, referenceMap);
}
}
}
示例9: testBlackListInfo
import java.io.DataOutput; //導入依賴的package包/類
/**
* test BlackListInfo class
*
* @throws IOException
*/
@Test (timeout=5000)
public void testBlackListInfo() throws IOException {
BlackListInfo info = new BlackListInfo();
info.setBlackListReport("blackListInfo");
info.setReasonForBlackListing("reasonForBlackListing");
info.setTrackerName("trackerName");
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
DataOutput out = new DataOutputStream(byteOut);
info.write(out);
BlackListInfo info2 = new BlackListInfo();
info2.readFields(new DataInputStream(new ByteArrayInputStream(byteOut
.toByteArray())));
assertEquals(info, info);
assertEquals(info.toString(), info.toString());
assertEquals(info.getTrackerName(), "trackerName");
assertEquals(info.getReasonForBlackListing(), "reasonForBlackListing");
assertEquals(info.getBlackListReport(), "blackListInfo");
}
示例10: write
import java.io.DataOutput; //導入依賴的package包/類
@Override
public void write(DataOutput out) throws IOException {
super.write(out);
// Write out the number of entries in the map
out.writeInt(instance.size());
// Then write out each key/value pair
for (Map.Entry<WritableComparable, Writable> e: instance.entrySet()) {
out.writeByte(getId(e.getKey().getClass()));
e.getKey().write(out);
out.writeByte(getId(e.getValue().getClass()));
e.getValue().write(out);
}
}
示例11: toData
import java.io.DataOutput; //導入依賴的package包/類
@Override
public void toData(DataOutput out) throws IOException {
out.writeBoolean(isRequestForEntireConfiguration);
int size = groups.size();
out.writeInt(size);
if (size > 0) {
for (String group : groups) {
out.writeUTF(group);
}
}
out.writeInt(numAttempts);
}
示例12: NbtFactory
import java.io.DataOutput; //導入依賴的package包/類
/**
* Construct an instance of the NBT factory by deducing the class of NBTBase.
*/
private NbtFactory() {
if (BASE_CLASS == null) {
try {
// Keep in mind that I do use hard-coded field names - but it's okay as long as we're dealing
// with CraftBukkit or its derivatives. This does not work in MCPC+ however.
ClassLoader loader = NbtFactory.class.getClassLoader();
String packageName = getPackageName();
Class<?> offlinePlayer = loader.loadClass(packageName + ".CraftOfflinePlayer");
// Prepare NBT
COMPOUND_CLASS = getMethod(0, Modifier.STATIC, offlinePlayer, "getData").getReturnType();
BASE_CLASS = COMPOUND_CLASS.getSuperclass();
NBT_GET_TYPE = getMethod(0, Modifier.STATIC, BASE_CLASS, "getTypeId");
NBT_CREATE_TAG = getMethod(Modifier.STATIC, 0, BASE_CLASS, "createTag", byte.class);
// Prepare CraftItemStack
CRAFT_STACK = loader.loadClass(packageName + ".inventory.CraftItemStack");
CRAFT_HANDLE = getField(null, CRAFT_STACK, "handle");
STACK_TAG = getField(null, CRAFT_HANDLE.getType(), "tag");
// Loading/saving
String nmsPackage = BASE_CLASS.getPackage().getName();
initializeNMS(loader, nmsPackage);
LOAD_COMPOUND = READ_LIMITER_CLASS != null ?
new LoadMethodSkinUpdate(STREAM_TOOLS, READ_LIMITER_CLASS) :
new LoadMethodWorldUpdate(STREAM_TOOLS);
SAVE_COMPOUND = getMethod(Modifier.STATIC, 0, STREAM_TOOLS, null, BASE_CLASS, DataOutput.class);
} catch (ClassNotFoundException e) {
throw new IllegalStateException("Unable to find offline player.", e);
}
}
}
示例13: writePayload
import java.io.DataOutput; //導入依賴的package包/類
@Override
protected void writePayload(DataOutput output, ByteBuffer header, boolean shrink)
throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ByteBuffer offsets = ByteBuffer.allocate(getOffsetSize()).order(ByteOrder.LITTLE_ENDIAN);
try (LittleEndianDataOutputStream payload = new LittleEndianDataOutputStream(baos)) {
writeEntries(payload, offsets, shrink);
}
output.write(offsets.array());
output.write(baos.toByteArray());
}
示例14: writeBloom
import java.io.DataOutput; //導入依賴的package包/類
/**
* Writes just the bloom filter to the output array
* @param out OutputStream to place bloom
* @throws IOException Error writing bloom array
*/
public void writeBloom(final DataOutput out) throws IOException {
if (!this.bloom.hasArray()) {
throw new IOException("Only writes ByteBuffer with underlying array.");
}
out.write(bloom.array(), bloom.arrayOffset(), bloom.limit());
}
示例15: toData
import java.io.DataOutput; //導入依賴的package包/類
@Override
public void toData(DataOutput out) throws IOException {
super.toData(out);
DataSerializer.writeObject(this.eventID, out);
DataSerializer.writePrimitiveInt(this.serialNum, out);
DataSerializer.writePrimitiveBoolean(this.notifyOfRegionDeparture, out);
DataSerializer.writeHashMap(this.subregionSerialNumbers, out);
}