当前位置: 首页>>代码示例>>Java>>正文


Java DataOutput.write方法代码示例

本文整理汇总了Java中java.io.DataOutput.write方法的典型用法代码示例。如果您正苦于以下问题:Java DataOutput.write方法的具体用法?Java DataOutput.write怎么用?Java DataOutput.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.io.DataOutput的用法示例。


在下文中一共展示了DataOutput.write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeEntries

import java.io.DataOutput; //导入方法依赖的package包/类
private int writeEntries(DataOutput payload, ByteBuffer offsets, boolean shrink)
    throws IOException {
  int entryOffset = 0;
  for (int i = 0; i < entryCount; ++i) {
    Entry entry = entries.get(i);
    if (entry == null) {
      offsets.putInt(Entry.NO_ENTRY);
    } else {
      byte[] encodedEntry = entry.toByteArray(shrink);
      payload.write(encodedEntry);
      offsets.putInt(entryOffset);
      entryOffset += encodedEntry.length;
    }
  }
  entryOffset = writePad(payload, entryOffset);
  return entryOffset;
}
 
开发者ID:xyxyLiu,项目名称:AndResM,代码行数:18,代码来源:TypeChunk.java

示例2: encrypt

import java.io.DataOutput; //导入方法依赖的package包/类
@Override
byte[] encrypt(byte[] key, byte[] data) {
  try {
    SecretKeySpec keySpec = new SecretKeySpec(key, AES);
    cipher.init(Cipher.ENCRYPT_MODE, keySpec);
    byte[] ciphertext = cipher.doFinal(data);

    // Write out the metadata.
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    DataOutput out = new DataOutputStream(stream);

    byte[] params = cipher.getParameters().getEncoded();
    WritableUtils.writeVInt(out, params.length);
    out.write(params);

    // Write the original ciphertext and return the new ciphertext.
    out.write(ciphertext);
    return stream.toByteArray();
  } catch (InvalidKeyException | IllegalBlockSizeException | BadPaddingException | IOException e) {
    throw new EncryptionException(e);
  }
}
 
开发者ID:mit-ll,项目名称:PACE,代码行数:23,代码来源:AESValueEncryptor.java

示例3: write

import java.io.DataOutput; //导入方法依赖的package包/类
public void write(DataOutput out) throws IOException {
  if (firstKey == null) {
    Utils.writeVInt(out, 0);
    return;
  }

  DataOutputBuffer dob = new DataOutputBuffer();
  Utils.writeVInt(dob, firstKey.size());
  dob.write(firstKey.buffer());
  Utils.writeVInt(out, dob.size());
  out.write(dob.getData(), 0, dob.getLength());

  for (TFileIndexEntry entry : index) {
    dob.reset();
    entry.write(dob);
    Utils.writeVInt(out, dob.getLength());
    out.write(dob.getData(), 0, dob.getLength());
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:20,代码来源:TFile.java

示例4: 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;
}
 
开发者ID:addertheblack,项目名称:myster,代码行数:21,代码来源:DownloaderThread.java

示例5: writePixel

import java.io.DataOutput; //导入方法依赖的package包/类
/**
 * The reverse function of {@link #readPixel(DataInput)}
 *
 * @param src the bitmap
 * @param dst the sink
 * @throws IOException
 */
public static void writePixel(@Nullable Bitmap src, DataOutput dst) throws IOException {
    if (src != null && src.getConfig() != Config.ARGB_8888) {
        throw new Panic("only bitmaps of the type ARGB_8888 are supported");
    }
    dst.writeBoolean(src != null);
    if (src == null) {
        return;
    }
    dst.writeInt(src.getWidth());
    dst.writeInt(src.getHeight());
    int bytes = src.getWidth() * src.getHeight() * 4;
    dst.writeByte(src.getConfig().ordinal());
    synchronized (BitmapPoolFactory.class) {
        if (sTmp.capacity() < bytes) {
            sTmp = ByteBuffer.allocate(bytes);
        }
        sTmp.clear();
        sTmp.limit(bytes);
        src.copyPixelsToBuffer(sTmp);
        dst.write(sTmp.array(), 0, bytes);
    }
}
 
开发者ID:worldiety,项目名称:homunculus,代码行数:30,代码来源:BitmapPoolFactory.java

示例6: write

import java.io.DataOutput; //导入方法依赖的package包/类
@Override
public void write(DataOutput out) throws IOException {
  super.write(out);
  byte[] bytes = new byte[getNBytes()];
  for(int i = 0, byteIndex = 0, bitIndex = 0; i < vectorSize; i++, bitIndex++) {
    if (bitIndex == 8) {
      bitIndex = 0;
      byteIndex++;
    }
    if (bitIndex == 0) {
      bytes[byteIndex] = 0;
    }
    if (bits.get(i)) {
      bytes[byteIndex] |= bitvalues[bitIndex];
    }
  }
  out.write(bytes);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:19,代码来源:BloomFilter.java

示例7: sendTo

import java.io.DataOutput; //导入方法依赖的package包/类
@Override
public void sendTo(DataOutput out) throws IOException {
  if (isSerialized()) {
    out.write(getSerializedValue());
  } else {
    Object objToSend = (byte[]) getDeserializedForReading(); // deserialized as a byte[]
    DataSerializer.writeObject(objToSend, out);
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:10,代码来源:AbstractStoredObject.java

示例8: writeNonRoot

import java.io.DataOutput; //导入方法依赖的package包/类
/**
 * Writes the block index chunk in the non-root index block format. This
 * format contains the number of entries, an index of integer offsets
 * for quick binary search on variable-length records, and tuples of
 * block offset, on-disk block size, and the first key for each entry.
 *
 * @param out
 * @throws IOException
 */
void writeNonRoot(DataOutput out) throws IOException {
  // The number of entries in the block.
  out.writeInt(blockKeys.size());

  if (secondaryIndexOffsetMarks.size() != blockKeys.size()) {
    throw new IOException("Corrupted block index chunk writer: " +
        blockKeys.size() + " entries but " +
        secondaryIndexOffsetMarks.size() + " secondary index items");
  }

  // For each entry, write a "secondary index" of relative offsets to the
  // entries from the end of the secondary index. This works, because at
  // read time we read the number of entries and know where the secondary
  // index ends.
  for (int currentSecondaryIndex : secondaryIndexOffsetMarks)
    out.writeInt(currentSecondaryIndex);

  // We include one other element in the secondary index to calculate the
  // size of each entry more easily by subtracting secondary index elements.
  out.writeInt(curTotalNonRootEntrySize);

  for (int i = 0; i < blockKeys.size(); ++i) {
    out.writeLong(blockOffsets.get(i));
    out.writeInt(onDiskDataSizes.get(i));
    out.write(blockKeys.get(i));
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:37,代码来源:HFileBlockIndex.java

示例9: writePayload

import java.io.DataOutput; //导入方法依赖的package包/类
@Override
protected void writePayload(DataOutput output, ByteBuffer header, boolean shrink)
    throws IOException {
  super.writePayload(output, header, shrink);
  output.writeInt(rawValue);
  output.write(resourceValue.toByteArray());
}
 
开发者ID:xyxyLiu,项目名称:AndResM,代码行数:8,代码来源:XmlCdataChunk.java

示例10: writeTo

import java.io.DataOutput; //导入方法依赖的package包/类
/**
 * Write the contents of a buffer to an output stream. The bytes are copied from the current position
 * in the buffer.
 * @param out The output to write to
 * @param buffer The buffer to write from
 * @param length The number of bytes to write
 * @throws IOException For any errors writing to the output
 */
public static void writeTo(DataOutput out, ByteBuffer buffer, int length) throws IOException {
    if (buffer.hasArray()) {
        out.write(buffer.array(), buffer.position() + buffer.arrayOffset(), length);
    } else {
        int pos = buffer.position();
        for (int i = pos; i < length + pos; i++)
            out.writeByte(buffer.get(i));
    }
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:18,代码来源:Utils.java

示例11: writePayload

import java.io.DataOutput; //导入方法依赖的package包/类
@Override
protected void writePayload(final DataOutput dataOutput)
        throws IOException {
    final int identOffset = 8 + 4 * 11;
    final int teamOffset = identOffset + identifierBytes.length;
    final int hashOffset = teamOffset + teamIdentifierBytes.length
                                       + specialSlots.length;
    final int pageSizeShift = 31 - Integer.numberOfLeadingZeros(pageSize);

    dataOutput.writeInt(0x20200); // version
    dataOutput.writeInt(flags);
    dataOutput.writeInt(hashOffset);
    dataOutput.writeInt(identOffset);
    dataOutput.writeInt(numberOfSpecialSlots);
    dataOutput.writeInt(numberOfCodeSlots);
    dataOutput.writeInt(codeLimit);
    dataOutput.writeByte(hashSize);
    dataOutput.writeByte(hashType);
    dataOutput.writeByte(0); // spare1
    dataOutput.writeByte(pageSizeShift);
    dataOutput.writeInt(0); // spare2
    dataOutput.writeInt(0); // scatterOffset
    dataOutput.writeInt(teamOffset);

    dataOutput.write(identifierBytes);
    dataOutput.write(teamIdentifierBytes);
    dataOutput.write(specialSlots);
    dataOutput.write(codeSlots);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:30,代码来源:CodeDirectoryBlob.java

示例12: write

import java.io.DataOutput; //导入方法依赖的package包/类
@Override
public void write(DataOutput out) throws IOException {
  byte[] name = this.tableName.toBytes();
  out.writeInt(name.length);
  out.write(name);
  out.writeInt(startRow);
  out.writeInt(rows);
  out.writeInt(totalRows);
  out.writeInt(clients);
  out.writeBoolean(flushCommits);
  out.writeBoolean(writeToWAL);
  out.writeBoolean(useTags);
  out.writeInt(noOfTags);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:15,代码来源:PerformanceEvaluation.java

示例13: toData

import java.io.DataOutput; //导入方法依赖的package包/类
@Override
public boolean toData(Object o, DataOutput out) throws IOException {
  out.write(tempField);
  return false;
}
 
开发者ID:ampool,项目名称:monarch,代码行数:6,代码来源:DataSerializerPropogationDUnitTest.java

示例14: write

import java.io.DataOutput; //导入方法依赖的package包/类
@Override
public void write(DataOutput out) throws IOException {
  byte[] pbBytes = toBytes();
  out.writeInt(pbBytes.length);
  out.write(pbBytes);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:7,代码来源:AuthenticationTokenIdentifier.java

示例15: write

import java.io.DataOutput; //导入方法依赖的package包/类
public void write(final DataOutput out) throws IOException {
  out.writeInt(this.length);
  out.write(this.bytes, this.offset, this.length);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:5,代码来源:ImmutableBytesWritable.java


注:本文中的java.io.DataOutput.write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。