本文整理了Java中okio.Buffer.inputStream()
方法的一些代码示例,展示了Buffer.inputStream()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Buffer.inputStream()
方法的具体详情如下:
包路径:okio.Buffer
类名称:Buffer
方法名:inputStream
暂无
代码示例来源:origin: square/okio
private Object deserialize(ByteString byteString) throws IOException, ClassNotFoundException {
Buffer buffer = new Buffer();
buffer.write(byteString);
try (ObjectInputStream objectIn = new ObjectInputStream(buffer.inputStream())) {
Object result = objectIn.readObject();
if (objectIn.read() != -1) throw new IOException("Unconsumed bytes in stream");
return result;
}
}
代码示例来源:origin: square/okhttp
private List<Certificate> readCertificateList(BufferedSource source) throws IOException {
int length = readInt(source);
if (length == -1) return Collections.emptyList(); // OkHttp v1.2 used -1 to indicate null.
try {
CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
List<Certificate> result = new ArrayList<>(length);
for (int i = 0; i < length; i++) {
String line = source.readUtf8LineStrict();
Buffer bytes = new Buffer();
bytes.write(ByteString.decodeBase64(line));
result.add(certificateFactory.generateCertificate(bytes.inputStream()));
}
return result;
} catch (CertificateException e) {
throw new IOException(e.getMessage());
}
}
代码示例来源:origin: k9mail/k-9
private static String charsetDecode(EncodedWord word) {
try {
InputStream inputStream = new Buffer().write(word.data).inputStream();
return CharsetSupport.readToString(inputStream, word.charset);
} catch (IOException e) {
return null;
}
}
代码示例来源:origin: square/okhttp
.writeUtf8(comodoRsaCertificationAuthority)
.writeUtf8(entrustRootCertificateAuthority)
.inputStream();
代码示例来源:origin: com.squareup.okhttp3/okhttp
private List<Certificate> readCertificateList(BufferedSource source) throws IOException {
int length = readInt(source);
if (length == -1) return Collections.emptyList(); // OkHttp v1.2 used -1 to indicate null.
try {
CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
List<Certificate> result = new ArrayList<>(length);
for (int i = 0; i < length; i++) {
String line = source.readUtf8LineStrict();
Buffer bytes = new Buffer();
bytes.write(ByteString.decodeBase64(line));
result.add(certificateFactory.generateCertificate(bytes.inputStream()));
}
return result;
} catch (CertificateException e) {
throw new IOException(e.getMessage());
}
}
代码示例来源:origin: apollographql/apollo-android
private List<Certificate> readCertificateList(BufferedSource source) throws IOException {
int length = readInt(source);
if (length == -1) return Collections.emptyList(); // OkHttp v1.2 used -1 to indicate null.
try {
CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
List<Certificate> result = new ArrayList<>(length);
for (int i = 0; i < length; i++) {
String line = source.readUtf8LineStrict();
Buffer bytes = new Buffer();
bytes.write(ByteString.decodeBase64(line));
result.add(certificateFactory.generateCertificate(bytes.inputStream()));
}
return result;
} catch (CertificateException e) {
throw new IOException(e.getMessage());
}
}
代码示例来源:origin: square/wire
public static Object deserialize(ByteString data) throws Exception {
Buffer buffer = new Buffer().write(data);
ObjectInputStream stream = new ObjectInputStream(buffer.inputStream());
return stream.readObject();
}
}
代码示例来源:origin: k9mail/k-9
private InputStream inputStream(String data) {
return new Buffer().writeUtf8(data).inputStream();
}
}
代码示例来源:origin: square/okio
@Test public void bufferInputStreamBulkReads() throws Exception {
Buffer source = new Buffer();
source.writeUtf8("abc");
byte[] byteArray = new byte[4];
Arrays.fill(byteArray, (byte) -5);
InputStream in = source.inputStream();
assertEquals(3, in.read(byteArray));
assertEquals("[97, 98, 99, -5]", Arrays.toString(byteArray));
Arrays.fill(byteArray, (byte) -7);
assertEquals(-1, in.read(byteArray));
assertEquals("[-7, -7, -7, -7]", Arrays.toString(byteArray));
}
代码示例来源:origin: square/okio
/**
* Uses streaming decompression to inflate {@code deflated}. The input must
* either be finished or have a trailing sync flush.
*/
private Buffer inflate(Buffer deflated) throws IOException {
InputStream deflatedIn = deflated.inputStream();
Inflater inflater = new Inflater();
InputStream inflatedIn = new InflaterInputStream(deflatedIn, inflater);
Buffer result = new Buffer();
byte[] buffer = new byte[8192];
while (!inflater.needsInput() || deflated.size() > 0 || deflatedIn.available() > 0) {
int count = inflatedIn.read(buffer, 0, buffer.length);
if (count != -1) {
result.write(buffer, 0, count);
}
}
return result;
}
}
代码示例来源:origin: square/okio
@Test public void bufferInputStreamByteByByte() throws Exception {
Buffer source = new Buffer();
source.writeUtf8("abc");
InputStream in = source.inputStream();
assertEquals(3, in.available());
assertEquals('a', in.read());
assertEquals('b', in.read());
assertEquals('c', in.read());
assertEquals(-1, in.read());
assertEquals(0, in.available());
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void upload_file() throws Exception {
answerHelloWorld();
File reportFile = temp.newFile();
FileUtils.write(reportFile, "the report content");
PostRequest request = new PostRequest("api/report/upload")
.setParam("project", "theKey")
.setPart("report", new PostRequest.Part(MediaTypes.TXT, reportFile))
.setMediaType(MediaTypes.PROTOBUF);
underTest = HttpConnector.newBuilder().url(serverUrl).build();
WsResponse response = underTest.call(request);
assertThat(response.hasContent()).isTrue();
RecordedRequest recordedRequest = server.takeRequest();
assertThat(recordedRequest.getMethod()).isEqualTo("POST");
assertThat(recordedRequest.getPath()).isEqualTo("/api/report/upload?project=theKey");
String body = IOUtils.toString(recordedRequest.getBody().inputStream());
assertThat(body)
.contains("Content-Disposition: form-data; name=\"report\"")
.contains("Content-Type: text/plain")
.contains("the report content");
}
代码示例来源:origin: fabric8io/kubernetes-client
if (request.body() != null && !request.method().equalsIgnoreCase(PATCH)) {
request.body().writeTo(buffer);
Object object = Serialization.unmarshal(buffer.inputStream());
if (object instanceof HasMetadata) {
HasMetadata h = (HasMetadata) object;
代码示例来源:origin: ZhuoKeTeam/QPM
private String getRequestContent(RequestBody body) throws IOException {
Buffer buffer = new Buffer();
body.writeTo(buffer);
BufferedReader reader = new BufferedReader(new InputStreamReader(buffer.inputStream()));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line);
}
return sb.toString();
}
代码示例来源:origin: gotify/android
public static InputStream stringToInputStream(String str) {
if (str == null) return null;
return new Buffer().writeUtf8(str).inputStream();
}
}
代码示例来源:origin: jenkinsci/jira-steps-plugin
@Override
public InputStream getMessagePayload() throws IOException {
if (request.body() == null) {
return null;
}
Buffer buf = new Buffer();
request.body().writeTo(buf);
return buf.inputStream();
}
代码示例来源:origin: com.vmware.card-connectors/core-test
private static ClientHttpRequest toRequest(RecordedRequest request) throws IOException {
MockClientHttpRequest clientRequest = new MockClientHttpRequest();
clientRequest.setMethod(HttpMethod.valueOf(request.getMethod()));
clientRequest.setURI(URI.create(request.getPath()));
request.getHeaders().toMultimap().forEach((name, values) ->
values.forEach(value -> clientRequest.getHeaders().add(name, value)));
IOUtils.copy(request.getBody().inputStream(), clientRequest.getBody());
return clientRequest;
}
代码示例来源:origin: auth0/auth0-java
public static Map<String, Object> bodyFromRequest(RecordedRequest request) throws IOException {
ObjectMapper mapper = new ObjectMapper();
MapType mapType = mapper.getTypeFactory().constructMapType(HashMap.class, String.class, Object.class);
Buffer body = request.getBody();
try {
return mapper.readValue(body.inputStream(), mapType);
} catch (IOException e) {
throw e;
} finally {
body.close();
}
}
}
代码示例来源:origin: segmentio/analytics-android
@Test
public void readFully() throws IOException {
assertThat(Utils.readFully(Utils.buffer(new Buffer().writeUtf8("foo\nbar").inputStream())))
.isEqualTo("foobar");
}
}
代码示例来源:origin: segmentio/analytics-android
@Test
public void noneCryptoRead() throws IOException {
Crypto crypto = Crypto.none();
ByteString foo = ByteString.encodeUtf8("foo");
Buffer buffer = new Buffer();
buffer.write(foo);
assertThat(Okio.buffer(Okio.source(crypto.decrypt(buffer.inputStream()))).readByteString()) //
.isEqualTo(foo);
}
}
内容来源于网络,如有侵权,请联系作者删除!