本文整理了Java中java.io.DataOutputStream.writeInt()
方法的一些代码示例,展示了DataOutputStream.writeInt()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DataOutputStream.writeInt()
方法的具体详情如下:
包路径:java.io.DataOutputStream
类名称:DataOutputStream
方法名:writeInt
[英]Writes an int
to the underlying output stream as four bytes, high byte first. If no exception is thrown, the counter written
is incremented by 4
.
[中]将int
作为四个字节写入基础输出流,高字节优先。如果未引发异常,计数器written
将递增4
。
代码示例来源:origin: apache/incubator-dubbo
@Override
public void writeBytes(byte[] v) throws IOException {
dos.writeInt(v.length);
dos.write(v);
}
代码示例来源:origin: hankcs/HanLP
@Override
public void save(DataOutputStream out) throws IOException
{
out.writeUTF(template);
out.writeInt(offsetList.size());
for (int[] offset : offsetList)
{
out.writeInt(offset[0]);
out.writeInt(offset[1]);
}
out.writeInt(delimiterList.size());
for (String s : delimiterList)
{
out.writeUTF(s);
}
}
代码示例来源:origin: redisson/redisson
void write(DataOutputStream out) throws IOException {
out.writeShort(name);
out.writeInt(info.length);
if (info.length > 0)
out.write(info);
}
代码示例来源:origin: aws/aws-sdk-java
private byte[] getPrelude(int totalLength) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream(8);
DataOutputStream dos = new DataOutputStream(baos);
int headerLength = totalLength - Message.MESSAGE_OVERHEAD - payload.length;
dos.writeInt(totalLength);
dos.writeInt(headerLength);
dos.close();
return baos.toByteArray();
}
代码示例来源:origin: redisson/redisson
ByteArrayOutputStream bIn = new ByteArrayOutputStream(1000); // 1000 should be large enough to fit the entire class
try {
in = new DataOutputStream(bIn);
in.write(MAGIC);
in.write(VERSION);
in.writeShort(CONSTANT_POOL_COUNT);
in.writeUTF(CONSTRUCTOR_NAME);
in.writeUTF(CONSTRUCTOR_DESC);
in.writeUTF("Code");
in.writeInt(CODE_ATTRIBUTE_LENGTH); // attribute length
in.writeShort(1); // max_stack
in.writeShort(1); // max_locals
in.writeInt(CODE.length); // code length
in.write(CODE);
in.writeShort(0); // exception_table_length = 0
in.writeShort(0); // attributes count = 0, no need to have LineNumberTable and LocalVariableTable
return bIn.toByteArray();
代码示例来源:origin: wildfly/wildfly
public static byte[] createAuthenticationDigest(String passcode,long t1,double q1) throws IOException,
NoSuchAlgorithmException {
ByteArrayOutputStream baos=new ByteArrayOutputStream(512);
DataOutputStream out=new DataOutputStream(baos);
byte[] digest=createDigest(passcode,t1,q1);
out.writeLong(t1);
out.writeDouble(q1);
out.writeInt(digest.length);
out.write(digest);
out.flush();
return baos.toByteArray();
}
代码示例来源:origin: voldemort/voldemort
public byte[] getBytes() {
try {
ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
DataOutputStream output = new DataOutputStream(byteOutput);
output.writeByte(opCode);
if(opCode != VoldemortOpCode.GET_OP_CODE)
output.write(version.toBytes());
output.writeUTF(key);
if(opCode == VoldemortOpCode.PUT_OP_CODE) {
output.writeInt(value.length);
output.write(value);
}
return byteOutput.toByteArray();
} catch(IOException e) {
throw new SerializationException(e);
}
}
代码示例来源:origin: apache/flume
@Deprecated
static ByteBuffer toByteBufferV2(TransactionEventRecord record) {
ByteArrayOutputStream byteOutput = new ByteArrayOutputStream(512);
DataOutputStream dataOutput = new DataOutputStream(byteOutput);
try {
dataOutput.writeInt(MAGIC_HEADER);
dataOutput.writeShort(record.getRecordType());
dataOutput.writeLong(record.getTransactionID());
dataOutput.writeLong(record.getLogWriteOrderID());
record.write(dataOutput);
dataOutput.flush();
// TODO toByteArray does an unneeded copy
return ByteBuffer.wrap(byteOutput.toByteArray());
} catch (IOException e) {
// near impossible
throw Throwables.propagate(e);
} finally {
if (dataOutput != null) {
try {
dataOutput.close();
} catch (IOException e) {
LOG.warn("Error closing byte array output stream", e);
}
}
}
}
代码示例来源:origin: apache/nifi
private byte[] serialize(final Map<String, String> stateValues) throws IOException {
try (final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final DataOutputStream dos = new DataOutputStream(baos)) {
dos.writeByte(ENCODING_VERSION);
dos.writeInt(stateValues.size());
for (final Map.Entry<String, String> entry : stateValues.entrySet()) {
final boolean hasKey = entry.getKey() != null;
final boolean hasValue = entry.getValue() != null;
dos.writeBoolean(hasKey);
if (hasKey) {
dos.writeUTF(entry.getKey());
}
dos.writeBoolean(hasValue);
if (hasValue) {
dos.writeUTF(entry.getValue());
}
}
return baos.toByteArray();
}
}
代码示例来源:origin: google/ExoPlayer
private static void doTestSerializationV0RoundTrip(HlsDownloadAction action) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
DataOutputStream output = new DataOutputStream(out);
DataOutputStream dataOutputStream = new DataOutputStream(output);
dataOutputStream.writeUTF(action.type);
dataOutputStream.writeInt(/* version */ 0);
dataOutputStream.writeUTF(action.uri.toString());
dataOutputStream.writeBoolean(action.isRemoveAction);
dataOutputStream.writeInt(action.data.length);
dataOutputStream.write(action.data);
dataOutputStream.writeInt(action.keys.size());
for (int i = 0; i < action.keys.size(); i++) {
StreamKey key = action.keys.get(i);
dataOutputStream.writeInt(key.groupIndex);
dataOutputStream.writeInt(key.trackIndex);
}
dataOutputStream.flush();
assertEqual(action, deserializeActionFromStream(out));
}
代码示例来源:origin: greenrobot/essentials
@Test
public void testUpdateInt() throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
new DataOutputStream(out).writeInt(1234567890);
long expected = getHashAndReset(out);
primitiveDataChecksum.updateInt(1234567890);
Assert.assertEquals(expected, primitiveDataChecksum.getValue());
}
代码示例来源:origin: hankcs/HanLP
static boolean saveDat(String path, TreeMap<String, String> map)
{
Collection<String> dependencyList = map.values();
// 缓存值文件
try
{
DataOutputStream out = new DataOutputStream(IOUtil.newOutputStream(path + ".bi" + Predefine.BIN_EXT));
out.writeInt(dependencyList.size());
for (String dependency : dependencyList)
{
out.writeUTF(dependency);
}
if (!trie.save(out)) return false;
out.close();
}
catch (Exception e)
{
logger.warning("保存失败" + e);
return false;
}
return true;
}
代码示例来源:origin: hankcs/HanLP
public boolean save(String fileName)
{
DataOutputStream out;
try
{
out = new DataOutputStream(new BufferedOutputStream(IOUtil.newOutputStream(fileName)));
out.writeInt(size);
for (int i = 0; i < size; i++)
{
out.writeInt(base[i]);
out.writeInt(check[i]);
}
out.close();
}
catch (Exception e)
{
return false;
}
return true;
}
代码示例来源:origin: libgdx/libgdx
/** Writes the ETC1Data with a PKM header to the given file.
* @param file the file. */
public void write (FileHandle file) {
DataOutputStream write = null;
byte[] buffer = new byte[10 * 1024];
int writtenBytes = 0;
compressedData.position(0);
compressedData.limit(compressedData.capacity());
try {
write = new DataOutputStream(new GZIPOutputStream(file.write(false)));
write.writeInt(compressedData.capacity());
while (writtenBytes != compressedData.capacity()) {
int bytesToWrite = Math.min(compressedData.remaining(), buffer.length);
compressedData.get(buffer, 0, bytesToWrite);
write.write(buffer, 0, bytesToWrite);
writtenBytes += bytesToWrite;
}
} catch (Exception e) {
throw new GdxRuntimeException("Couldn't write PKM file to '" + file + "'", e);
} finally {
StreamUtils.closeQuietly(write);
}
compressedData.position(dataOffset);
compressedData.limit(compressedData.capacity());
}
代码示例来源:origin: hankcs/HanLP
DataOutputStream out = new DataOutputStream(IOUtil.newOutputStream(path + Predefine.BIN_EXT));
out.writeInt(attributeList.size());
for (Attribute attribute : attributeList)
out.writeInt(attribute.p.length);
for (int i = 0; i < attribute.p.length; ++i)
out.writeInt(charArray.length);
for (char c : charArray)
out.close();
代码示例来源:origin: google/guava
private void initializeData(DataOutputStream out) throws IOException {
/* Write out various test values NORMALLY */
out.write(new byte[] {-100, 100});
out.writeBoolean(true);
out.writeBoolean(false);
out.writeByte(100);
out.writeByte(-100);
out.writeByte((byte) 200);
out.writeChar('a');
out.writeShort((short) -30000);
out.writeShort((short) 50000);
out.writeInt(0xCAFEBABE);
out.writeLong(0xDEADBEEFCAFEBABEL);
out.writeUTF("Herby Derby");
out.writeFloat(Float.intBitsToFloat(0xCAFEBABE));
out.writeDouble(Double.longBitsToDouble(0xDEADBEEFCAFEBABEL));
}
代码示例来源:origin: wildfly/wildfly
public void writeState(OutputStream outstream) throws IOException {
if(state == null)
return;
synchronized(state) {
DataOutputStream dos = new DataOutputStream(outstream);
dos.writeInt(state.size());
Point point;
Color col;
for (Map.Entry<Point, Color> entry : state.entrySet()) {
point = entry.getKey();
col = entry.getValue();
dos.writeInt(point.x);
dos.writeInt(point.y);
dos.writeInt(col.getRGB());
}
dos.flush();
}
}
代码示例来源:origin: skylot/jadx
public void test(OutputStream output) throws IOException {
DataOutputStream out = new DataOutputStream(output);
try {
out.writeByte(1);
out.writeInt(classes.length);
for (NClass cls : classes) {
writeString(out, cls.getName());
}
for (NClass cls : classes) {
NClass[] parents = cls.getParents();
out.writeByte(parents.length);
for (NClass parent : parents) {
out.writeInt(parent.getId());
}
}
} finally {
out.close();
}
}
代码示例来源:origin: skylot/jadx
public void save(OutputStream output) throws IOException {
try (DataOutputStream out = new DataOutputStream(output)) {
out.writeBytes(JADX_CLS_SET_HEADER);
out.writeByte(VERSION);
LOG.info("Classes count: {}", classes.length);
out.writeInt(classes.length);
for (NClass cls : classes) {
writeString(out, cls.getName());
}
for (NClass cls : classes) {
NClass[] parents = cls.getParents();
out.writeByte(parents.length);
for (NClass parent : parents) {
out.writeInt(parent.getId());
}
}
}
}
代码示例来源:origin: google/guava
/**
* Writes this {@code BloomFilter} to an output stream, with a custom format (not Java
* serialization). This has been measured to save at least 400 bytes compared to regular
* serialization.
*
* <p>Use {@linkplain #readFrom(InputStream, Funnel)} to reconstruct the written BloomFilter.
*/
public void writeTo(OutputStream out) throws IOException {
// Serial form:
// 1 signed byte for the strategy
// 1 unsigned byte for the number of hash functions
// 1 big endian int, the number of longs in our bitset
// N big endian longs of our bitset
DataOutputStream dout = new DataOutputStream(out);
dout.writeByte(SignedBytes.checkedCast(strategy.ordinal()));
dout.writeByte(UnsignedBytes.checkedCast(numHashFunctions)); // note: checked at the c'tor
dout.writeInt(bits.data.length());
for (int i = 0; i < bits.data.length(); i++) {
dout.writeLong(bits.data.get(i));
}
}
内容来源于网络,如有侵权,请联系作者删除!