Java Code Examples for org.springframework.core.io.buffer.DataBuffer#write()
The following examples show how to use
org.springframework.core.io.buffer.DataBuffer#write() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MultipartHttpMessageWriter.java From java-technology-stack with MIT License | 6 votes |
private DataBuffer generateHeaders() { DataBuffer buffer = this.bufferFactory.allocateBuffer(); for (Map.Entry<String, List<String>> entry : this.headers.entrySet()) { byte[] headerName = entry.getKey().getBytes(this.charset); for (String headerValueString : entry.getValue()) { byte[] headerValue = headerValueString.getBytes(this.charset); buffer.write(headerName); buffer.write((byte)':'); buffer.write((byte)' '); buffer.write(headerValue); buffer.write((byte)'\r'); buffer.write((byte)'\n'); } } buffer.write((byte)'\r'); buffer.write((byte)'\n'); return buffer; }
Example 2
Source File: ServletServerHttpRequest.java From java-technology-stack with MIT License | 6 votes |
/** * Read from the request body InputStream and return a DataBuffer. * Invoked only when {@link ServletInputStream#isReady()} returns "true". * @return a DataBuffer with data read, or {@link #EOF_BUFFER} if the input * stream returned -1, or null if 0 bytes were read. */ @Nullable DataBuffer readFromInputStream() throws IOException { int read = this.request.getInputStream().read(this.buffer); logBytesRead(read); if (read > 0) { DataBuffer dataBuffer = this.bufferFactory.allocateBuffer(read); dataBuffer.write(this.buffer, 0, read); return dataBuffer; } if (read == -1) { return EOF_BUFFER; } return null; }
Example 3
Source File: ServletServerHttpRequest.java From spring-analysis-note with MIT License | 6 votes |
/** * Read from the request body InputStream and return a DataBuffer. * Invoked only when {@link ServletInputStream#isReady()} returns "true". * @return a DataBuffer with data read, or {@link #EOF_BUFFER} if the input * stream returned -1, or null if 0 bytes were read. */ @Nullable DataBuffer readFromInputStream() throws IOException { int read = this.request.getInputStream().read(this.buffer); logBytesRead(read); if (read > 0) { DataBuffer dataBuffer = this.bufferFactory.allocateBuffer(read); dataBuffer.write(this.buffer, 0, read); return dataBuffer; } if (read == -1) { return EOF_BUFFER; } return null; }
Example 4
Source File: MultipartHttpMessageWriter.java From java-technology-stack with MIT License | 5 votes |
private DataBuffer generateBoundaryLine(byte[] boundary) { DataBuffer buffer = this.bufferFactory.allocateBuffer(boundary.length + 4); buffer.write((byte)'-'); buffer.write((byte)'-'); buffer.write(boundary); buffer.write((byte)'\r'); buffer.write((byte)'\n'); return buffer; }
Example 5
Source File: CharSequenceEncoder.java From spring-analysis-note with MIT License | 5 votes |
@Override public DataBuffer encodeValue(CharSequence charSequence, DataBufferFactory bufferFactory, ResolvableType valueType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) { if (!Hints.isLoggingSuppressed(hints)) { LogFormatUtils.traceDebug(logger, traceOn -> { String formatted = LogFormatUtils.formatValue(charSequence, !traceOn); return Hints.getLogPrefix(hints) + "Writing " + formatted; }); } boolean release = true; Charset charset = getCharset(mimeType); int capacity = calculateCapacity(charSequence, charset); DataBuffer dataBuffer = bufferFactory.allocateBuffer(capacity); try { dataBuffer.write(charSequence, charset); release = false; } catch (CoderMalfunctionError ex) { throw new EncodingException("String encoding error: " + ex.getMessage(), ex); } finally { if (release) { DataBufferUtils.release(dataBuffer); } } return dataBuffer; }
Example 6
Source File: JettyClientHttpConnector.java From java-technology-stack with MIT License | 5 votes |
private DataBuffer toDataBuffer(ContentChunk chunk) { // We must copy until this is resolved: // https://github.com/eclipse/jetty.project/issues/2429 // Use copy instead of buffer wrapping because Callback#succeeded() is // used not only to release the buffer but also to request more data // which is a problem for codecs that buffer data. DataBuffer buffer = this.bufferFactory.allocateBuffer(chunk.buffer.capacity()); buffer.write(chunk.buffer); chunk.callback.succeeded(); return buffer; }
Example 7
Source File: DataBufferTestUtilsTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void dumpBytes() { DataBuffer buffer = this.bufferFactory.allocateBuffer(4); byte[] source = {'a', 'b', 'c', 'd'}; buffer.write(source); byte[] result = DataBufferTestUtils.dumpBytes(buffer); assertArrayEquals(source, result); release(buffer); }
Example 8
Source File: MultipartHttpMessageWriter.java From java-technology-stack with MIT License | 5 votes |
private DataBuffer generateLastLine(byte[] boundary) { DataBuffer buffer = this.bufferFactory.allocateBuffer(boundary.length + 6); buffer.write((byte)'-'); buffer.write((byte)'-'); buffer.write(boundary); buffer.write((byte)'-'); buffer.write((byte)'-'); buffer.write((byte)'\r'); buffer.write((byte)'\n'); return buffer; }
Example 9
Source File: RandomHandlerIntegrationTests.java From java-technology-stack with MIT License | 5 votes |
private DataBuffer randomBuffer(int size) { byte[] bytes = new byte[size]; rnd.nextBytes(bytes); DataBuffer buffer = dataBufferFactory.allocateBuffer(size); buffer.write(bytes); return buffer; }
Example 10
Source File: SynchronossPartHttpMessageReader.java From spring-analysis-note with MIT License | 5 votes |
@Override public Flux<DataBuffer> content() { byte[] bytes = this.content.getBytes(getCharset()); DataBuffer buffer = getBufferFactory().allocateBuffer(bytes.length); buffer.write(bytes); return Flux.just(buffer); }
Example 11
Source File: JettyClientHttpConnector.java From spring-analysis-note with MIT License | 5 votes |
private DataBuffer toDataBuffer(ContentChunk chunk) { // We must copy until this is resolved: // https://github.com/eclipse/jetty.project/issues/2429 // Use copy instead of buffer wrapping because Callback#succeeded() is // used not only to release the buffer but also to request more data // which is a problem for codecs that buffer data. DataBuffer buffer = this.bufferFactory.allocateBuffer(chunk.buffer.capacity()); buffer.write(chunk.buffer); chunk.callback.succeeded(); return buffer; }
Example 12
Source File: DataBufferTestUtilsTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void dumpString() { DataBuffer buffer = this.bufferFactory.allocateBuffer(4); String source = "abcd"; buffer.write(source.getBytes(StandardCharsets.UTF_8)); String result = DataBufferTestUtils.dumpString(buffer, StandardCharsets.UTF_8); assertEquals(source, result); release(buffer); }
Example 13
Source File: SynchronossPartHttpMessageReader.java From java-technology-stack with MIT License | 5 votes |
@Override public Flux<DataBuffer> content() { byte[] bytes = this.content.getBytes(getCharset()); DataBuffer buffer = getBufferFactory().allocateBuffer(bytes.length); buffer.write(bytes); return Flux.just(buffer); }
Example 14
Source File: WriteOnlyHandlerIntegrationTests.java From spring-analysis-note with MIT License | 4 votes |
@Override public Mono<Void> handle(ServerHttpRequest request, ServerHttpResponse response) { DataBuffer buffer = response.bufferFactory().allocateBuffer(body.length); buffer.write(body); return response.writeAndFlushWith(Flux.just(Flux.just(buffer))); }
Example 15
Source File: Jackson2TokenizerTests.java From spring-analysis-note with MIT License | 4 votes |
private DataBuffer stringBuffer(String value) { byte[] bytes = value.getBytes(StandardCharsets.UTF_8); DataBuffer buffer = this.bufferFactory.allocateBuffer(bytes.length); buffer.write(bytes); return buffer; }
Example 16
Source File: ServerSentEventHttpMessageReaderTests.java From spring-analysis-note with MIT License | 4 votes |
private DataBuffer stringBuffer(String value) { byte[] bytes = value.getBytes(StandardCharsets.UTF_8); DataBuffer buffer = this.bufferFactory.allocateBuffer(bytes.length); buffer.write(bytes); return buffer; }
Example 17
Source File: FormHttpMessageReaderTests.java From java-technology-stack with MIT License | 4 votes |
private DataBuffer stringBuffer(String value) { byte[] bytes = value.getBytes(StandardCharsets.UTF_8); DataBuffer buffer = this.bufferFactory.allocateBuffer(bytes.length); buffer.write(bytes); return buffer; }
Example 18
Source File: ApiVersionWebFilter.java From spring-cloud-open-service-broker with Apache License 2.0 | 4 votes |
private DataBuffer toDataBuffer(String value, DataBufferFactory factory) { byte[] data = value.getBytes(StandardCharsets.UTF_8); DataBuffer buffer = factory.allocateBuffer(data.length); buffer.write(data); return buffer; }
Example 19
Source File: ServerSentEventHttpMessageReaderTests.java From java-technology-stack with MIT License | 4 votes |
private DataBuffer stringBuffer(String value) { byte[] bytes = value.getBytes(StandardCharsets.UTF_8); DataBuffer buffer = this.bufferFactory.allocateBuffer(bytes.length); buffer.write(bytes); return buffer; }
Example 20
Source File: Jackson2TokenizerTests.java From java-technology-stack with MIT License | 4 votes |
private DataBuffer stringBuffer(String value) { byte[] bytes = value.getBytes(StandardCharsets.UTF_8); DataBuffer buffer = this.bufferFactory.allocateBuffer(bytes.length); buffer.write(bytes); return buffer; }