本文整理汇总了Java中java.io.DataOutputStream.writeInt方法的典型用法代码示例。如果您正苦于以下问题:Java DataOutputStream.writeInt方法的具体用法?Java DataOutputStream.writeInt怎么用?Java DataOutputStream.writeInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.DataOutputStream
的用法示例。
在下文中一共展示了DataOutputStream.writeInt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: clientWork
import java.io.DataOutputStream; //导入方法依赖的package包/类
/**
* Writes the seat in the socket and reads the returned student info.
*
* @see Client#clientWork(InputStream, OutputStream);
*/
@Override
protected void clientWork(InputStream inputStream, OutputStream outputStream) {
try {
DataOutputStream writer = new DataOutputStream(outputStream);
DataInputStream reader = new DataInputStream(inputStream);
writer.writeUTF(Constants.TEACHER_TOKEN);
writer.writeInt(seat);
int count = reader.readInt();
byte[] bytes = new byte[count];
reader.readFully(bytes);
studentInfo = StudentInfo.deserialize(bytes);
writer.close();
reader.close();
} catch (Exception ignored) {
}
}
示例2: testCopyOnWrite
import java.io.DataOutputStream; //导入方法依赖的package包/类
@Test
public void testCopyOnWrite() throws IOException
{
ByteArrayOutputStream writeTo = new ByteArrayOutputStream();
ByteArrayOutputStream copyTo = new ByteArrayOutputStream();
DataOutputStream copyOnWriteOutputStream = new DataOutputStream(new CopyOnWriteOutputStream(writeTo, copyTo));
copyOnWriteOutputStream.writeInt(5);
copyOnWriteOutputStream.writeInt(10);
copyOnWriteOutputStream.close();
DataInputStream dataInputStream = new DataInputStream(new ByteArrayInputStream(writeTo.toByteArray()));
Assert.assertEquals(5L, dataInputStream.readInt());
Assert.assertEquals(10L, dataInputStream.readInt());
DataInputStream dataInputStream2 = new DataInputStream(new ByteArrayInputStream(copyTo.toByteArray()));
Assert.assertEquals(5L, dataInputStream2.readInt());
Assert.assertEquals(10L, dataInputStream2.readInt());
}
示例3: serialize
import java.io.DataOutputStream; //导入方法依赖的package包/类
public static void serialize(final BinSerializable serializable, final OutputStream output)
throws IOException {
DataOutputStream out = new DataOutputStream(output);
try {
out.write(HEADER);
out.writeInt(VERSION);
serializable.write(out);
} finally {
try {
out.close();
} catch (IOException ignored) { }
}
}
示例4: write
import java.io.DataOutputStream; //导入方法依赖的package包/类
@Override
protected void write(DataOutputStream outputStream) throws Exception {
outputStream.writeLong(nextBlock.getPos());
outputStream.writeInt(largestInNextBlock);
outputStream.writeInt(entries.size());
for (FreeListEntry entry : entries) {
outputStream.writeLong(entry.pos.getPos());
outputStream.writeInt(entry.size);
}
}
示例5: write
import java.io.DataOutputStream; //导入方法依赖的package包/类
public void write(DataOutputStream outstr) throws IOException {
outstr.writeInt(entries.size());
for (IndexEntry entry : entries) {
outstr.writeLong(entry.hashCode);
outstr.writeLong(entry.dataBlock.getPos());
outstr.writeLong(entry.childIndexBlock.getPos());
}
outstr.writeLong(tailPos.getPos());
}
示例6: writeOut
import java.io.DataOutputStream; //导入方法依赖的package包/类
public void writeOut(DataOutputStream out) throws IOException
{
out.writeInt(desc.data.length);
for(BrightFeature ft:desc.data)
{
out.writeInt(ft.value.length);
for(double val:ft.value)
{
out.writeDouble(val);
}
}
hash.writeOut(out);
}
示例7: JdpPacketWriter
import java.io.DataOutputStream; //导入方法依赖的package包/类
/**
* Create a JDP packet, add mandatory magic and version headers
*
* @throws IOException
*/
public JdpPacketWriter()
throws IOException {
baos = new ByteArrayOutputStream();
pkt = new DataOutputStream(baos);
pkt.writeInt(JdpGenericPacket.getMagic());
pkt.writeShort(JdpGenericPacket.getVersion());
}
示例8: dump
import java.io.DataOutputStream; //导入方法依赖的package包/类
/**
* Dump instruction as byte code to stream out.
* @param out Output stream
*/
@Override
public void dump( final DataOutputStream out ) throws IOException {
super.setIndex(getTargetOffset());
out.writeByte(super.getOpcode());
out.writeInt(super.getIndex());
}
示例9: save
import java.io.DataOutputStream; //导入方法依赖的package包/类
@Override
public void save(DataOutputStream out) throws Exception {
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);
}
}
示例10: wrapWithSasl
import java.io.DataOutputStream; //导入方法依赖的package包/类
private static void wrapWithSasl(ByteArrayOutputStream response, Call call)
throws IOException {
if (call.connection.saslServer != null) {
byte[] token = call.rpcResponse.array();
// synchronization may be needed since there can be multiple Handler
// threads using saslServer to wrap responses.
synchronized (call.connection.saslServer) {
token = call.connection.saslServer.wrap(token, 0, token.length);
}
if (LOG.isDebugEnabled())
LOG.debug("Adding saslServer wrapped token of size " + token.length
+ " as call response.");
response.reset();
// rebuild with sasl header and payload
RpcResponseHeaderProto saslHeader = RpcResponseHeaderProto.newBuilder()
.setCallId(AuthProtocol.SASL.callId)
.setStatus(RpcStatusProto.SUCCESS)
.build();
RpcSaslProto saslMessage = RpcSaslProto.newBuilder()
.setState(SaslState.WRAP)
.setToken(ByteString.copyFrom(token, 0, token.length))
.build();
RpcResponseMessageWrapper saslResponse =
new RpcResponseMessageWrapper(saslHeader, saslMessage);
DataOutputStream out = new DataOutputStream(response);
out.writeInt(saslResponse.getLength());
saslResponse.write(out);
}
}
示例11: write
import java.io.DataOutputStream; //导入方法依赖的package包/类
@Override
public void write(DataOutputStream output) throws IOException {
output.writeBoolean(getValue().hasDisplayName());
if(getValue().hasDisplayName()) {
output.writeUTF(getValue().getDisplayName());
}
output.writeBoolean(getValue().hasLocalizedName());
if(getValue().hasLocalizedName()) {
output.writeUTF(getValue().getLocalizedName());
}
ArrayListStorage<StringStorage> loreStorage = new ArrayListStorage<StringStorage>(getValue().hasLore() ? getValue().getLore().stream().map(StringStorage::new).collect(Collectors.toList()) : new ArrayList<>());
loreStorage.write(output);
output.writeInt(getValue().getEnchants().size());
Map<EnchantmentStorage, IntStorage> storages = new HashMap<>();
getValue().getEnchants().forEach((enchantment, level) -> storages.put(new EnchantmentStorage(enchantment), new IntStorage(level)));
HashMapStorage<EnchantmentStorage, IntStorage> enchantStorage = new HashMapStorage<EnchantmentStorage, IntStorage>(storages);
enchantStorage.write(output);
output.writeInt(getValue().getItemFlags().size());
for(ItemFlag flag : getValue().getItemFlags()) {
output.writeUTF(flag.toString());
}
output.writeBoolean(getValue().isUnbreakable());
}
示例12: writeToStream
import java.io.DataOutputStream; //导入方法依赖的package包/类
public void writeToStream(DataOutputStream out) throws IOException {
super.writeToStream(out);
out.writeInt(objectsCounts.length);
for (int i = 0; i < objectsCounts.length; i++) {
out.writeInt(objectsCounts[i]);
}
}
示例13: writeTransportHeader
import java.io.DataOutputStream; //导入方法依赖的package包/类
/**
* Send transport header over stream.
*/
private void writeTransportHeader(DataOutputStream out)
throws RemoteException
{
try {
// write out transport header
DataOutputStream dataOut =
new DataOutputStream(out);
dataOut.writeInt(TransportConstants.Magic);
dataOut.writeShort(TransportConstants.Version);
} catch (IOException e) {
throw new ConnectIOException(
"error writing JRMP transport header", e);
}
}
示例14: createRowKey
import java.io.DataOutputStream; //导入方法依赖的package包/类
static byte[] createRowKey(int keyPart1, int keyPart2) {
ByteArrayOutputStream bos = new ByteArrayOutputStream(16);
DataOutputStream dos = new DataOutputStream(bos);
try {
dos.writeInt(keyPart1);
dos.writeInt(keyPart2);
} catch (IOException e) {
// should not happen
throw new RuntimeException(e);
}
return bos.toByteArray();
}
示例15: save
import java.io.DataOutputStream; //导入方法依赖的package包/类
@Override
public void save(DataOutputStream out) throws IOException
{
ArrayList<Vec3> list = new ArrayList<>();
for (WireNode n = first; n != null; n = n.next) list.add(n.pos);
out.writeInt(list.size());
for (Vec3 v : list) v.write(out);
}