/** * Returns whether the {@link #length()} is 0. */ default boolean isEmpty() { return length() == 0; }
@Override protected void onRemoval(HttpObject obj) { if (obj instanceof HttpData) { final int length = ((HttpData) obj).length(); inboundTrafficController.dec(length); } }
@Override protected void onRemoval(HttpObject obj) { if (obj instanceof HttpData) { final int length = ((HttpData) obj).length(); assert inboundTrafficController != null; inboundTrafficController.dec(length); } } }
@Override protected HttpObject filter(HttpObject obj) { if (obj instanceof HttpData) { final int dataLength = ((HttpData) obj).length(); contentLength += dataLength; if (contentLength >= contentPreviewLength) { assert subscription != null; subscription.cancel(); } } return obj; } }
private HttpDataFile(HttpData content, @Nullable MediaType contentType, Clock clock, HttpFileAttributes attrs, boolean dateEnabled, boolean lastModifiedEnabled, @Nullable BiFunction<String, HttpFileAttributes, String> entityTagFunction, HttpHeaders headers) { super(contentType, clock, dateEnabled, lastModifiedEnabled, entityTagFunction, headers); this.content = content; this.attrs = attrs; }
/** * Decodes this data into a {@link String}. * * @param charset the {@link Charset} to use for decoding this data * * @return the decoded {@link String} */ default String toString(Charset charset) { requireNonNull(charset, "charset"); return new String(array(), offset(), length(), charset); }
/** * Converts an {@link HttpData} into a {@link DataBuffer}. */ DataBuffer toDataBuffer(HttpData httpData) { requireNonNull(httpData, "httpData"); if (!(httpData instanceof ByteBufHttpData)) { return delegate.wrap( ByteBuffer.wrap(httpData.array(), httpData.offset(), httpData.length())); } return converter.apply((ByteBufHttpData) httpData); }
@Override public boolean tryWrite(HttpObject obj) { final boolean published = super.tryWrite(obj); if (published && obj instanceof HttpData) { final int length = ((HttpData) obj).length(); assert inboundTrafficController != null; inboundTrafficController.inc(length); writtenBytes += length; } return published; }
@Override public void messageRead(ByteBufOrStream message) { // We know there is only one message in total, so don't bother with checking endOfStream // We also know that we don't support compression, so this is always a ByteBuffer. final HttpData unframedContent = new ByteBufHttpData(message.buf(), true); unframedHeaders.setInt(HttpHeaderNames.CONTENT_LENGTH, unframedContent.length()); res.complete(HttpResponse.of(unframedHeaders, unframedContent)); }
@Override public int doRead(ApplicationBufferHandler handler) throws IOException { if (!isNeedToRead()) { // Read only once. return -1; } read = true; final int readableBytes = content.length(); handler.setByteBuffer(ByteBuffer.wrap(content.array(), content.offset(), readableBytes)); return readableBytes; }
/** * Returns a new {@link InputStream} that is sourced from this data. */ default InputStream toInputStream() { return new FastByteArrayInputStream(array(), offset(), length()); }
@Override void onHttpData(HttpData data) { responseDataBuffer.write(data.array(), data.offset(), data.length()); }
@Override public int doRead(ByteChunk chunk, Request request) throws IOException { if (read || content.isEmpty()) { // Read only once. return -1; } read = true; final int readableBytes = content.length(); chunk.setBytes(content.array(), content.offset(), readableBytes); return readableBytes; } }
public int doRead(ByteChunk chunk) { if (!isNeedToRead()) { // Read only once. return -1; } read = true; final int readableBytes = content.length(); chunk.setBytes(content.array(), content.offset(), readableBytes); return readableBytes; }
@Override public boolean tryWrite(HttpObject obj) { final boolean published = super.tryWrite(obj); if (published && obj instanceof HttpData) { final int length = ((HttpData) obj).length(); inboundTrafficController.inc(length); assert ctx != null : "uninitialized DecodedHttpRequest must be aborted."; ctx.logBuilder().requestLength(transferredBytes); } return published; }
private void fail(int id, HttpResponseStatus status) { discarding = true; req = null; final HttpData data = HttpData.ofUtf8(status.toString()); final com.linecorp.armeria.common.HttpHeaders headers = com.linecorp.armeria.common.HttpHeaders.of(status.code()); headers.set(HttpHeaderNames.CONNECTION, "close"); headers.setObject(HttpHeaderNames.CONTENT_TYPE, MediaType.PLAIN_TEXT_UTF_8); headers.setInt(HttpHeaderNames.CONTENT_LENGTH, data.length()); writer.writeHeaders(id, 1, headers, false); writer.writeData(id, 1, data, true).addListener(ChannelFutureListener.CLOSE); }
@Override public HttpData decode(HttpData obj) { if (obj instanceof ByteBufHolder) { decoder.writeInbound(((ByteBufHolder) obj).content()); } else { final ByteBuf compressed = Unpooled.wrappedBuffer(obj.array(), obj.offset(), obj.length()); decoder.writeInbound(compressed); } return HttpData.of(fetchDecoderOutput()); }
private void invoke(THttpService service) throws Exception { invoke0(service, HttpData.of(out.getArray(), 0, out.length()), promise); final HttpData res = promise.get(); in.reset(res.array(), res.offset(), res.length()); }
private static void fillRequest( ServiceRequestContext ctx, AggregatedHttpMessage aReq, Request jReq) { jReq.setDispatcherType(DispatcherType.REQUEST); jReq.setAsyncSupported(false, "armeria"); jReq.setSecure(ctx.sessionProtocol().isTls()); jReq.setMetaData(toRequestMetadata(ctx, aReq)); final HttpData content = aReq.content(); if (!content.isEmpty()) { jReq.getHttpInput().addContent(new Content(ByteBuffer.wrap( content.array(), content.offset(), content.length()))); } jReq.getHttpInput().eof(); }