本文整理匯總了Java中com.google.protobuf.CodedOutputStream.flush方法的典型用法代碼示例。如果您正苦於以下問題:Java CodedOutputStream.flush方法的具體用法?Java CodedOutputStream.flush怎麽用?Java CodedOutputStream.flush使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.protobuf.CodedOutputStream
的用法示例。
在下文中一共展示了CodedOutputStream.flush方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: encode
import com.google.protobuf.CodedOutputStream; //導入方法依賴的package包/類
@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception
{
if (!(msg instanceof ChannelBuffer))
{
return msg;
}
ChannelBuffer body = (ChannelBuffer) msg;
int length = body.readableBytes();
ChannelBuffer header = channel.getConfig().getBufferFactory()
.getBuffer(body.order(), CodedOutputStream.computeRawVarint64Size(length) + 4);
CodedOutputStream codedOutputStream = CodedOutputStream.newInstance(new ChannelBufferOutputStream(header));
codedOutputStream.writeRawVarint64(length);
int value = 0x0;
value |= (0x0 & 0xff);// network version
value |= ((0x0 & 0xff) << 8);// type
if (ctx.getPipeline().get("cryptoEncoder") != null) value |= ((0x1 & 0xf) << 16);// crypto type
else value |= ((0x0 & 0xf) << 16);// crypto type
value |= ((0x0 & 0xfff) << 20);// version
codedOutputStream.writeRawLittleEndian32(value);
codedOutputStream.flush();
return wrappedBuffer(header, body);
}
示例2: saveProperties
import com.google.protobuf.CodedOutputStream; //導入方法依賴的package包/類
/**
* Saves track properties by modifying only file tail.
*/
public void saveProperties(FileDataSource source) throws Exception {
Track track = source.tracks.get(0);
// Prepare new properties tail
ByteBuffer buffer = ByteBuffer.allocate(getSerializedPropertiesSize(track));
CodedOutputStream output = CodedOutputStream.newInstance(buffer);
output.writeBytes(FIELD_NAME, ByteString.copyFromUtf8(track.name));
output.writeUInt32(FIELD_COLOR, track.style.color);
output.writeFloat(FIELD_WIDTH, track.style.width);
output.flush();
// Modify tail of file
File file = new File(source.path);
long createTime = file.lastModified();
RandomAccessFile access = new RandomAccessFile(file, "rw");
access.setLength(source.propertiesOffset + 1);
access.seek(source.propertiesOffset);
access.write(buffer.array());
access.close();
//noinspection ResultOfMethodCallIgnored
file.setLastModified(createTime);
}
示例3: toProtos
import com.google.protobuf.CodedOutputStream; //導入方法依賴的package包/類
private static <T> List<byte[]> toProtos(ProtobufCodec<T> codec, Collection<T> objs)
throws OrmException {
List<byte[]> result = Lists.newArrayListWithCapacity(objs.size());
ByteArrayOutputStream out = new ByteArrayOutputStream(256);
try {
for (T obj : objs) {
out.reset();
CodedOutputStream cos = CodedOutputStream.newInstance(out);
codec.encode(obj, cos);
cos.flush();
result.add(out.toByteArray());
}
} catch (IOException e) {
throw new OrmException(e);
}
return result;
}
示例4: doInBackground
import com.google.protobuf.CodedOutputStream; //導入方法依賴的package包/類
@Override
protected eu.hellek.gba.proto.SearchResultProtos.SearchResultProxy doInBackground(Void... params) {
try {
URL url = new URL("http://"+appurl+"/rm/DirectSearchServlet");
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/x-protobuf");
conn.setRequestProperty("Content-Length", ""+req.getSerializedSize());
OutputStream out = conn.getOutputStream();
CodedOutputStream cout = CodedOutputStream.newInstance(out);
req.writeTo(cout);
cout.flush();
out.close();
eu.hellek.gba.proto.SearchResultProtos.SearchResultProxy srp = eu.hellek.gba.proto.SearchResultProtos.SearchResultProxy.parseFrom(conn.getInputStream());
return srp;
} catch(Exception e) {
Log.e("DirectSearchTask", "Error in search", e);
e.printStackTrace();
return null;
}
}
示例5: encodeWithLengthPrefix
import com.google.protobuf.CodedOutputStream; //導入方法依賴的package包/類
public static void encodeWithLengthPrefix(MessageLite msg, ByteBuf out) throws Exception {
ByteBuf msgBytes;
if(msg==null){
msgBytes=Unpooled.EMPTY_BUFFER;
}
else{
msgBytes=encodeNoLengthPrefix(msg);
}
int encodedMessageLen = msgBytes.readableBytes();
int headerLenLen = CodedOutputStream.computeRawVarint32Size(encodedMessageLen);
out.ensureWritable(headerLenLen + encodedMessageLen);
CodedOutputStream headerOut =
CodedOutputStream.newInstance(new ByteBufOutputStream(out), headerLenLen);
headerOut.writeRawVarint32(encodedMessageLen);
headerOut.flush();
out.writeBytes(msgBytes, msgBytes.readerIndex(), encodedMessageLen);
}
示例6: serializeOneNestedSet
import com.google.protobuf.CodedOutputStream; //導入方法依賴的package包/類
private void serializeOneNestedSet(
Object children, CodedOutputStream codedOut, Map<Object, byte[]> childToDigest)
throws IOException, SerializationException {
// Serialize nested set into an inner byte array so we can take its digest
ByteArrayOutputStream childOutputStream = new ByteArrayOutputStream();
HashingOutputStream hashingOutputStream =
new HashingOutputStream(Hashing.md5(), childOutputStream);
CodedOutputStream childCodedOut = CodedOutputStream.newInstance(hashingOutputStream);
if (children instanceof Object[]) {
serializeMultiItemChildArray((Object[]) children, childToDigest, childCodedOut);
} else if (children != NestedSet.EMPTY_CHILDREN) {
serializeSingleItemChildArray(children, childCodedOut);
} else {
// Empty set
childCodedOut.writeInt32NoTag(0);
}
childCodedOut.flush();
byte[] digest = hashingOutputStream.hash().asBytes();
codedOut.writeByteArrayNoTag(digest);
byte[] childBytes = childOutputStream.toByteArray();
codedOut.writeByteArrayNoTag(childBytes);
childToDigest.put(children, digest);
}
示例7: testSerializeDeserializeInBulk
import com.google.protobuf.CodedOutputStream; //導入方法依賴的package包/類
@Test
public void testSerializeDeserializeInBulk() throws Exception {
Integer value1 = 12345;
Integer value2 = 67890;
Integer value3 = 42;
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
CodedOutputStream codedOut = CodedOutputStream.newInstance(bytesOut);
underTest.serialize(KNOWN_CLASSIFIER, value1, codedOut);
underTest.serialize(KNOWN_CLASSIFIER, value2, codedOut);
underTest.serialize(KNOWN_CLASSIFIER, value3, codedOut);
codedOut.flush();
CodedInputStream codedIn = CodedInputStream.newInstance(bytesOut.toByteArray());
assertThat(underTest.deserialize(KNOWN_CLASSIFIER_BYTES, codedIn)).isEqualTo(value1);
assertThat(underTest.deserialize(KNOWN_CLASSIFIER_BYTES, codedIn)).isEqualTo(value2);
assertThat(underTest.deserialize(KNOWN_CLASSIFIER_BYTES, codedIn)).isEqualTo(value3);
}
示例8: encode
import com.google.protobuf.CodedOutputStream; //導入方法依賴的package包/類
@Override
protected void encode(
ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception {
int bodyLen = msg.readableBytes();
int headerLen = CodedOutputStream.computeRawVarint32Size(bodyLen);
out.ensureWritable(headerLen + bodyLen);
CodedOutputStream headerOut =
CodedOutputStream.newInstance(new ByteBufOutputStream(out), headerLen);
headerOut.writeRawVarint32(bodyLen);
headerOut.flush();
out.writeBytes(msg, msg.readerIndex(), bodyLen);
}
示例9: readRecordBytes
import com.google.protobuf.CodedOutputStream; //導入方法依賴的package包/類
public byte[] readRecordBytes() throws IOException {
in.resetSizeCounter();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
CodedOutputStream os = CodedOutputStream.newInstance(bos);
byte[] recordBytes = in.readByteArray();
os.writeByteArrayNoTag(recordBytes);
os.flush();
return bos.toByteArray();
}
示例10: makeConnectionMessage
import com.google.protobuf.CodedOutputStream; //導入方法依賴的package包/類
private static byte[] makeConnectionMessage(Counter.Value value)
throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
CodedOutputStream codedOutput = CodedOutputStream.newInstance(out);
codedOutput.writeRawLittleEndian32(value.getSerializedSize());
value.writeTo(codedOutput);
codedOutput.flush();
byte[] all = out.toByteArray();
return all;
}
示例11: doVarIntTest
import com.google.protobuf.CodedOutputStream; //導入方法依賴的package包/類
private void doVarIntTest(int value) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
CodedOutputStream cout = CodedOutputStream.newInstance(baos);
cout.writeRawVarint32(value);
cout.flush();
DataInputStream dis = new DataInputStream(
new ByteArrayInputStream(baos.toByteArray()));
assertEquals(value, ProtoUtil.readRawVarint32(dis));
}
示例12: encode
import com.google.protobuf.CodedOutputStream; //導入方法依賴的package包/類
protected void encode(ChannelHandlerContext paramChannelHandlerContext, ByteBuf paramByteBuf1, ByteBuf paramByteBuf2)
throws Exception {
int i = paramByteBuf1.readableBytes();
int j = CodedOutputStream.computeRawVarint32Size(i);
paramByteBuf2.ensureWritable(j + i);
CodedOutputStream localCodedOutputStream = CodedOutputStream.newInstance(new ByteBufOutputStream(paramByteBuf2), j);
localCodedOutputStream.writeRawVarint32(i);
localCodedOutputStream.flush();
paramByteBuf2.writeBytes(paramByteBuf1, paramByteBuf1.readerIndex(), i);
}
示例13: encode
import com.google.protobuf.CodedOutputStream; //導入方法依賴的package包/類
protected void encode(ChannelHandlerContext paramChannelHandlerContext, ByteBuf paramByteBuf1, ByteBuf paramByteBuf2)
throws Exception {
int i = paramByteBuf1.readableBytes();
int j = CodedOutputStream.computeRawVarint32Size(i);
paramByteBuf2.ensureWritable(j + i);
CodedOutputStream localCodedOutputStream = CodedOutputStream.newInstance(new ByteBufOutputStream(paramByteBuf2), j);
localCodedOutputStream.writeRawVarint32(i);
localCodedOutputStream.flush();
paramByteBuf2.writeBytes(paramByteBuf1, paramByteBuf1.readerIndex(), i);
paramByteBuf2.release();
}
示例14: savePreprocessedBlock
import com.google.protobuf.CodedOutputStream; //導入方法依賴的package包/類
private void savePreprocessedBlock(BlockContext context, List<RtbImpression> impressions) throws IOException {
try (OutputStream os = context.createOutputStream(PREPROCESS)) {
CodedOutputStream cos = CodedOutputStream.newInstance(os);
for (RtbImpression impression : impressions) {
if (impression == null) continue;;
byte[] bytes = impression.toByteArray();
cos.writeUInt32NoTag(bytes.length);
cos.writeRawBytes(bytes);
}
cos.flush();
}
}
示例15: writeWallet
import com.google.protobuf.CodedOutputStream; //導入方法依賴的package包/類
/**
* Formats the given wallet (transactions and keys) to the given output stream in protocol buffer format.<p>
*
* Equivalent to <tt>walletToProto(wallet).writeTo(output);</tt>
*/
public void writeWallet(Wallet wallet, OutputStream output) throws IOException {
Protos.Wallet walletProto = walletToProto(wallet);
final CodedOutputStream codedOutput = CodedOutputStream.newInstance(output, this.walletWriteBufferSize);
walletProto.writeTo(codedOutput);
codedOutput.flush();
}