Return-Path: X-Original-To: apmail-felix-dev-archive@www.apache.org Delivered-To: apmail-felix-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D8C43106F6 for ; Mon, 6 Jan 2014 10:30:07 +0000 (UTC) Received: (qmail 48125 invoked by uid 500); 6 Jan 2014 10:29:54 -0000 Delivered-To: apmail-felix-dev-archive@felix.apache.org Received: (qmail 48070 invoked by uid 500); 6 Jan 2014 10:29:52 -0000 Mailing-List: contact dev-help@felix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@felix.apache.org Delivered-To: mailing list dev@felix.apache.org Received: (qmail 48055 invoked by uid 99); 6 Jan 2014 10:29:50 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 Jan 2014 10:29:50 +0000 Date: Mon, 6 Jan 2014 10:29:50 +0000 (UTC) From: "Tim Verbelen (JIRA)" To: dev@felix.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Comment Edited] (FELIX-4375) Error when reading gosh_profile from stream MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/FELIX-4375?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13862901#comment-13862901 ] Tim Verbelen edited comment on FELIX-4375 at 1/6/14 10:28 AM: -------------------------------------------------------------- Instead of using a large buffer when the stream length is unknown upfront, one could also use a StringBuffer : {code:java} private CharSequence readScript(URI script) throws Exception { URLConnection conn = script.toURL().openConnection(); int length = conn.getContentLength(); StringBuffer sbuf = new StringBuffer(); CharBuffer cbuf; if(length == -1) cbuf = CharBuffer.allocate(1024); else cbuf = CharBuffer.allocate(length); InputStream in = conn.getInputStream(); Reader reader = new InputStreamReader(in); while(reader.read(cbuf) > 0){ cbuf.flip(); sbuf.append(cbuf); cbuf.clear(); } in.close(); return sbuf; } {code} was (Author: tverbele): Instead of using a large buffer when the stream length is unknown upfront, one could also use a StringBuffer : private CharSequence readScript(URI script) throws Exception { URLConnection conn = script.toURL().openConnection(); int length = conn.getContentLength(); StringBuffer sbuf = new StringBuffer(); CharBuffer cbuf; if(length == -1) cbuf = CharBuffer.allocate(1024); else cbuf = CharBuffer.allocate(length); InputStream in = conn.getInputStream(); Reader reader = new InputStreamReader(in); while(reader.read(cbuf) > 0){ cbuf.flip(); sbuf.append(cbuf); cbuf.clear(); } in.close(); return sbuf; } > Error when reading gosh_profile from stream > ------------------------------------------- > > Key: FELIX-4375 > URL: https://issues.apache.org/jira/browse/FELIX-4375 > Project: Felix > Issue Type: Bug > Components: Gogo Shell > Affects Versions: gogo.shell-0.10.0 > Environment: Error occurred using Gogo shell on top op Concierge OSGi runtime. > Reporter: Tim Verbelen > Priority: Minor > > An error occurs when "gosh_profile" is read from a stream without knowing the lenght upfront. In that case, method `CharSequence readScript(URI script)` from `Shell.java` causes an error, since it does not correctly handle the case when the length is -1. In that case, a large size buffer is allocated (fixed on 10240 atm), and thus as the buffer will not be completely filled, one cannot use `cbuf.rewind()`, but use `cbuf.flip()` instead. -- This message was sent by Atlassian JIRA (v6.1.5#6160)