felix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tim Verbelen (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (FELIX-4375) Error when reading gosh_profile from stream
Date Mon, 06 Jan 2014 10:27:50 GMT

    [ https://issues.apache.org/jira/browse/FELIX-4375?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13862901#comment-13862901
] 

Tim Verbelen commented on FELIX-4375:
-------------------------------------

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)

Mime
View raw message