Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id AEC11200CA5 for ; Sat, 10 Jun 2017 17:17:25 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id AD674160BDA; Sat, 10 Jun 2017 15:17:25 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id F1D15160BD7 for ; Sat, 10 Jun 2017 17:17:24 +0200 (CEST) Received: (qmail 24054 invoked by uid 500); 10 Jun 2017 15:17:23 -0000 Mailing-List: contact dev-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list dev@hc.apache.org Received: (qmail 24043 invoked by uid 99); 10 Jun 2017 15:17:22 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 10 Jun 2017 15:17:22 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 248B7C0AF9 for ; Sat, 10 Jun 2017 15:17:22 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -100.011 X-Spam-Level: X-Spam-Status: No, score=-100.011 tagged_above=-999 required=6.31 tests=[SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id PgzPlP9HKX_L for ; Sat, 10 Jun 2017 15:17:19 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id 3501B5F569 for ; Sat, 10 Jun 2017 15:17:19 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 697C7E0663 for ; Sat, 10 Jun 2017 15:17:18 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 1F2322193D for ; Sat, 10 Jun 2017 15:17:18 +0000 (UTC) Date: Sat, 10 Jun 2017 15:17:18 +0000 (UTC) From: "Nicholas DiPiazza (JIRA)" To: dev@hc.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Created] (HTTPCLIENT-1854) Cannot peek contents of org.apache.http.conn.EofSensorInputStream MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Sat, 10 Jun 2017 15:17:25 -0000 Nicholas DiPiazza created HTTPCLIENT-1854: --------------------------------------------- Summary: Cannot peek contents of org.apache.http.conn.EofSensorInputStream Key: HTTPCLIENT-1854 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1854 Project: HttpComponents HttpClient Issue Type: Bug Affects Versions: 4.5.2 Reporter: Nicholas DiPiazza I am trying to peek at an input stream contents from HttpClient, up to 64k bytes. The stream comes from an HttpGet, nothing unusual about it: {code} HttpGet requestGet = new HttpGet(encodedUrl); HttpResponse httpResponse = httpClient.execute(requestGet); int status = httpResponse.getStatusLine().getStatusCode(); if (status == HttpStatus.SC_OK) { return httpResponse.getEntity().getContent(); } {code} The input stream it returns is of type org.apache.http.conn.EofSensorInputStream Our use-case is such that we need to "peek" at the first (up to 64k) bytes of the input stream. I use an algorithm described here How do I peek at the first two bytes in an InputStream? {code} PushbackInputStream pis = new PushbackInputStream(inputStream, DEFAULT_PEEK_BUFFER_SIZE); byte [] peekBytes = new byte[DEFAULT_PEEK_BUFFER_SIZE]; int read = pis.read(peekBytes); if (read < DEFAULT_PEEK_BUFFER_SIZE) { byte[] trimmed = new byte[read]; System.arraycopy(peekBytes, 0, trimmed, 0, read); peekBytes = trimmed; } pis.unread(peekBytes); {code} When I use a ByteArrayInputStream, this works with no problem. When using the org.apache.http.conn.EofSensorInputStream I only get a small number of bytes at the beginning of the stream. usually around 400 bytes. When I expected up to 64k bytes. I also tried using a BufferedInputStream where I read up to the first 64k bytes then call a .reset() but that doesn't work either. Same issue. Why might this be? I do not think anything is closing the stream because if you call IOUtils.toString(inputStream) I do get all the content. See https://stackoverflow.com/questions/44474191/is-it-possible-to-peek-httpclients-org-apache-http-conn-eofsensorinputstream -- This message was sent by Atlassian JIRA (v6.3.15#6346) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org For additional commands, e-mail: dev-help@hc.apache.org