本文整理了Java中okio.Buffer.<init>()
方法的一些代码示例,展示了Buffer.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Buffer.<init>()
方法的具体详情如下:
包路径:okio.Buffer
类名称:Buffer
方法名:<init>
暂无
代码示例来源:origin: square/okhttp
Http2Writer(BufferedSink sink, boolean client) {
this.sink = sink;
this.client = client;
this.hpackBuffer = new Buffer();
this.hpackWriter = new Hpack.Writer(hpackBuffer);
this.maxFrameSize = INITIAL_MAX_FRAME_SIZE;
}
代码示例来源:origin: square/retrofit
@Override public RequestBody convert(final T value) throws IOException {
Buffer buffer = new Buffer();
try {
Marshaller marshaller = context.createMarshaller();
XMLStreamWriter xmlWriter = xmlOutputFactory.createXMLStreamWriter(
buffer.outputStream(), JaxbConverterFactory.XML.charset().name());
marshaller.marshal(value, xmlWriter);
} catch (JAXBException | XMLStreamException e) {
throw new RuntimeException(e);
}
return RequestBody.create(JaxbConverterFactory.XML, buffer.readByteString());
}
}
代码示例来源:origin: square/retrofit
@Override public RequestBody convert(T value) throws IOException {
Buffer buffer = new Buffer();
adapter.encode(buffer, value);
return RequestBody.create(MEDIA_TYPE, buffer.snapshot());
}
}
代码示例来源:origin: square/okhttp
/** Returns a new response body that transmits {@code content}. */
public static ResponseBody create(final @Nullable MediaType contentType, byte[] content) {
Buffer buffer = new Buffer().write(content);
return create(contentType, content.length, buffer);
}
代码示例来源:origin: square/retrofit
@Override public RequestBody convert(T value) throws IOException {
Buffer buffer = new Buffer();
try {
OutputStreamWriter osw = new OutputStreamWriter(buffer.outputStream(), CHARSET);
serializer.write(value, osw);
osw.flush();
} catch (RuntimeException | IOException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
}
}
代码示例来源:origin: square/retrofit
static ResponseBody buffer(final ResponseBody body) throws IOException {
Buffer buffer = new Buffer();
body.source().readAll(buffer);
return ResponseBody.create(body.contentType(), body.contentLength(), buffer);
}
代码示例来源:origin: square/okhttp
private Buffer fileToBytes(File file) throws IOException {
Buffer result = new Buffer();
result.writeAll(Okio.source(file));
return result;
}
代码示例来源:origin: square/okhttp
/**
* Sets the response body to the UTF-8 encoded bytes of {@code body}, chunked every {@code
* maxChunkSize} bytes.
*/
public MockResponse setChunkedBody(String body, int maxChunkSize) {
return setChunkedBody(new Buffer().writeUtf8(body), maxChunkSize);
}
代码示例来源:origin: square/okhttp
/** Sets the response body to the UTF-8 encoded bytes of {@code body}. */
public MockResponse setBody(String body) {
return setBody(new Buffer().writeUtf8(body));
}
代码示例来源:origin: square/okhttp
static String percentDecode(String encoded, int pos, int limit, boolean plusIsSpace) {
for (int i = pos; i < limit; i++) {
char c = encoded.charAt(i);
if (c == '%' || (c == '+' && plusIsSpace)) {
// Slow path: the character at i requires decoding!
Buffer out = new Buffer();
out.writeUtf8(encoded, pos, i);
percentDecode(out, encoded, i, limit, plusIsSpace);
return out.readUtf8();
}
}
// Fast path: no characters in [pos..limit) required decoding.
return encoded.substring(pos, limit);
}
代码示例来源:origin: square/retrofit
@Override public RequestBody convert(T value) throws IOException {
Buffer buffer = new Buffer();
JsonWriter writer = JsonWriter.of(buffer);
adapter.toJson(writer, value);
return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
}
}
代码示例来源:origin: square/okhttp
/** Returns a new response body that transmits {@code content}. */
public static ResponseBody create(@Nullable MediaType contentType, ByteString content) {
Buffer buffer = new Buffer().write(content);
return create(contentType, content.size(), buffer);
}
代码示例来源:origin: square/okhttp
/**
* Returns the concatenation of 8-bit, length prefixed protocol names.
* http://tools.ietf.org/html/draft-agl-tls-nextprotoneg-04#page-4
*/
static byte[] concatLengthPrefixed(List<Protocol> protocols) {
Buffer result = new Buffer();
for (int i = 0, size = protocols.size(); i < size; i++) {
Protocol protocol = protocols.get(i);
if (protocol == Protocol.HTTP_1_0) continue; // No HTTP/1.0 for ALPN.
result.writeByte(protocol.toString().length());
result.writeUtf8(protocol.toString());
}
return result.readByteArray();
}
代码示例来源:origin: square/okhttp
private void writeMetadata(long upstreamSize) throws IOException {
Buffer metadataBuffer = new Buffer();
metadataBuffer.write(metadata);
FileOperator fileOperator = new FileOperator(file.getChannel());
fileOperator.write(FILE_HEADER_SIZE + upstreamSize, metadataBuffer, metadata.size());
}
代码示例来源:origin: square/retrofit
@Override public String convert(T value) throws IOException {
Buffer buffer = new Buffer();
delegate.convert(value).writeTo(buffer);
return buffer.readUtf8();
}
}
代码示例来源:origin: square/retrofit
@Override public RequestBody convert(T value) throws IOException {
Buffer buffer = new Buffer();
Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
JsonWriter jsonWriter = gson.newJsonWriter(writer);
adapter.write(jsonWriter, value);
jsonWriter.close();
return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
}
}
代码示例来源:origin: square/okhttp
/**
* Returns a new response body that transmits {@code content}. If {@code contentType} is non-null
* and lacks a charset, this will use UTF-8.
*/
public static ResponseBody create(@Nullable MediaType contentType, String content) {
Charset charset = UTF_8;
if (contentType != null) {
charset = contentType.charset();
if (charset == null) {
charset = UTF_8;
contentType = MediaType.parse(contentType + "; charset=utf-8");
}
}
Buffer buffer = new Buffer().writeString(content, charset);
return create(contentType, buffer.size(), buffer);
}
代码示例来源:origin: square/okhttp
private void writeHeader(
ByteString prefix, long upstreamSize, long metadataSize) throws IOException {
Buffer header = new Buffer();
header.write(prefix);
header.writeLong(upstreamSize);
header.writeLong(metadataSize);
if (header.size() != FILE_HEADER_SIZE) throw new IllegalArgumentException();
FileOperator fileOperator = new FileOperator(file.getChannel());
fileOperator.write(0, header, FILE_HEADER_SIZE);
}
代码示例来源:origin: square/okhttp
@Override public void writeTo(BufferedSink sink) throws IOException {
Buffer buffer = new Buffer();
while (pipe.source().read(buffer, 8192) != -1L) {
sink.write(buffer, buffer.size());
}
}
}
代码示例来源:origin: square/okhttp
void writeByteString(ByteString data) throws IOException {
if (useCompression && Huffman.get().encodedLength(data) < data.size()) {
Buffer huffmanBuffer = new Buffer();
Huffman.get().encode(data, huffmanBuffer);
ByteString huffmanBytes = huffmanBuffer.readByteString();
writeInt(huffmanBytes.size(), PREFIX_7_BITS, 0x80);
out.write(huffmanBytes);
} else {
writeInt(data.size(), PREFIX_7_BITS, 0);
out.write(data);
}
}
内容来源于网络,如有侵权,请联系作者删除!