You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "oliver z (JIRA)" <ji...@apache.org> on 2010/09/29 22:01:33 UTC

[jira] Created: (HTTPCLIENT-1004) EofSensorInputStreams available() always returns 0

EofSensorInputStreams available() always returns 0
--------------------------------------------------

                 Key: HTTPCLIENT-1004
                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1004
             Project: HttpComponents HttpClient
          Issue Type: Bug
          Components: HttpClient
    Affects Versions: 4.1 Alpha2
         Environment: win 7 x64, netbeans 6.9.1, jdk6_21
            Reporter: oliver  z


i just wrote a little mp3 audio player which retrieves a stream and plays it. 
to make sure the user does not play further than the song has been stored into ram, i thought i just use the available() method from the class EofSensorInputStream.
But this method always returns 0 (normal http connection), casting to a ByteArrayInputStream would be nice, but thats not working... so i took a look at the implementation of available():

http://www.docjar.com/html/api/org/apache/http/conn/EofSensorInputStream.java.html
  165       @Override
  166       public int available() throws IOException {
  167           int a = 0; // not -1
  168   
  169           if (isReadAllowed()) {
  170               try {
  171                   a = wrappedStream.available();
  172                   // no checkEOF() here, available() can't trigger EOF
  173               } catch (IOException ex) {
  174                   checkAbort();
  175                   throw ex;
  176               }
  177           }
  178   
  179           return a;
  180       }

wrappedStream is an InputStream, and InputStream says to available():
The available method for class InputStream always returns 0. 
This method should be overridden by subclasses. 

Im not sure if this is a bug or a feature request

Is there any other way how i can check how many bytes has been transfered into ram?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[jira] Issue Comment Edited: (HTTPCLIENT-1004) EofSensorInputStreams available() always returns 0

Posted by "oliver z (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1004?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12916550#action_12916550 ] 

oliver  z edited comment on HTTPCLIENT-1004 at 9/30/10 1:35 PM:
----------------------------------------------------------------

i am using HtmlUnit 2.8. I replaced the old HttpClient/HttpCore/HttpMime jars with the new one (4.1alpha2 and 4.1-beta2) and recompiled it. So i think HtmlUnit is using the new one, not the 4.0 version.

I tried to cast the InputStream to ContentLengthInputStream but i still get

Exception in thread "Thread-28" java.lang.ClassCastException: org.apache.http.conn.EofSensorInputStream cannot be cast to org.apache.http.impl.io.ContentLengthInputStream
        at myPlay.player.PlayThread$SongSlider.run(PlayThread.java:56)

I will take a closer look on this on the weekend.

edit: i just saw that htmlunit uses DefaultHttpClient, could this be somehow the problem?

      was (Author: olze84):
    i am using HtmlUnit 2.8. I replaced the old HttpClient/HttpCore/HttpMime jars with the new one (4.1alpha2 and 4.1-beta2) and recompiled it. So i think HtmlUnit is using the new one, not the 4.0 version.

I tried to cast the InputStream to ContentLengthInputStream but i still get

Exception in thread "Thread-28" java.lang.ClassCastException: org.apache.http.conn.EofSensorInputStream cannot be cast to org.apache.http.impl.io.ContentLengthInputStream
        at myPlay.player.PlayThread$SongSlider.run(PlayThread.java:56)

I will take a closer look on this on the weekend.
  
> EofSensorInputStreams available() always returns 0
> --------------------------------------------------
>
>                 Key: HTTPCLIENT-1004
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1004
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient
>    Affects Versions: 4.1 Alpha2
>         Environment: win 7 x64, netbeans 6.9.1, jdk6_21
>            Reporter: oliver  z
>
> i just wrote a little mp3 audio player which retrieves a stream and plays it. 
> to make sure the user does not play further than the song has been stored into ram, i thought i just use the available() method from the class EofSensorInputStream.
> But this method always returns 0 (normal http connection), casting to a ByteArrayInputStream would be nice, but thats not working... so i took a look at the implementation of available():
> http://www.docjar.com/html/api/org/apache/http/conn/EofSensorInputStream.java.html
>   165       @Override
>   166       public int available() throws IOException {
>   167           int a = 0; // not -1
>   168   
>   169           if (isReadAllowed()) {
>   170               try {
>   171                   a = wrappedStream.available();
>   172                   // no checkEOF() here, available() can't trigger EOF
>   173               } catch (IOException ex) {
>   174                   checkAbort();
>   175                   throw ex;
>   176               }
>   177           }
>   178   
>   179           return a;
>   180       }
> wrappedStream is an InputStream, and InputStream says to available():
> The available method for class InputStream always returns 0. 
> This method should be overridden by subclasses. 
> Im not sure if this is a bug or a feature request
> Is there any other way how i can check how many bytes has been transfered into ram?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[jira] Commented: (HTTPCLIENT-1004) EofSensorInputStreams available() always returns 0

Posted by "oliver z (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1004?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12916587#action_12916587 ] 

oliver  z commented on HTTPCLIENT-1004:
---------------------------------------

in the class BasicManagedEntity i just found this:

 @Override
    public InputStream getContent() throws IOException {
        return new EofSensorInputStream(wrappedEntity.getContent(), this);       
    }

thats where i get the EofSensorInputStream 

i will check this out these days if i can reproduce this problem with other mp3s 

> EofSensorInputStreams available() always returns 0
> --------------------------------------------------
>
>                 Key: HTTPCLIENT-1004
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1004
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient
>    Affects Versions: 4.1 Alpha2
>         Environment: win 7 x64, netbeans 6.9.1, jdk6_21
>            Reporter: oliver  z
>
> i just wrote a little mp3 audio player which retrieves a stream and plays it. 
> to make sure the user does not play further than the song has been stored into ram, i thought i just use the available() method from the class EofSensorInputStream.
> But this method always returns 0 (normal http connection), casting to a ByteArrayInputStream would be nice, but thats not working... so i took a look at the implementation of available():
> http://www.docjar.com/html/api/org/apache/http/conn/EofSensorInputStream.java.html
>   165       @Override
>   166       public int available() throws IOException {
>   167           int a = 0; // not -1
>   168   
>   169           if (isReadAllowed()) {
>   170               try {
>   171                   a = wrappedStream.available();
>   172                   // no checkEOF() here, available() can't trigger EOF
>   173               } catch (IOException ex) {
>   174                   checkAbort();
>   175                   throw ex;
>   176               }
>   177           }
>   178   
>   179           return a;
>   180       }
> wrappedStream is an InputStream, and InputStream says to available():
> The available method for class InputStream always returns 0. 
> This method should be overridden by subclasses. 
> Im not sure if this is a bug or a feature request
> Is there any other way how i can check how many bytes has been transfered into ram?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[jira] Commented: (HTTPCLIENT-1004) EofSensorInputStreams available() always returns 0

Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1004?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12916576#action_12916576 ] 

Oleg Kalnichevski commented on HTTPCLIENT-1004:
-----------------------------------------------

Then, the internal buffer is likely to be empty.

Oleg

> EofSensorInputStreams available() always returns 0
> --------------------------------------------------
>
>                 Key: HTTPCLIENT-1004
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1004
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient
>    Affects Versions: 4.1 Alpha2
>         Environment: win 7 x64, netbeans 6.9.1, jdk6_21
>            Reporter: oliver  z
>
> i just wrote a little mp3 audio player which retrieves a stream and plays it. 
> to make sure the user does not play further than the song has been stored into ram, i thought i just use the available() method from the class EofSensorInputStream.
> But this method always returns 0 (normal http connection), casting to a ByteArrayInputStream would be nice, but thats not working... so i took a look at the implementation of available():
> http://www.docjar.com/html/api/org/apache/http/conn/EofSensorInputStream.java.html
>   165       @Override
>   166       public int available() throws IOException {
>   167           int a = 0; // not -1
>   168   
>   169           if (isReadAllowed()) {
>   170               try {
>   171                   a = wrappedStream.available();
>   172                   // no checkEOF() here, available() can't trigger EOF
>   173               } catch (IOException ex) {
>   174                   checkAbort();
>   175                   throw ex;
>   176               }
>   177           }
>   178   
>   179           return a;
>   180       }
> wrappedStream is an InputStream, and InputStream says to available():
> The available method for class InputStream always returns 0. 
> This method should be overridden by subclasses. 
> Im not sure if this is a bug or a feature request
> Is there any other way how i can check how many bytes has been transfered into ram?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[jira] Issue Comment Edited: (HTTPCLIENT-1004) EofSensorInputStreams available() always returns 0

Posted by "oliver z (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1004?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12917289#action_12917289 ] 

oliver  z edited comment on HTTPCLIENT-1004 at 10/3/10 3:54 AM:
----------------------------------------------------------------

ok i got it, thanks.
Is there any way to achieve the behavior i need? would it be possible converting the EofSensorInputStream to an IdentityInputStream to get this or is IdentityInputStream also not  a read-ahead buffer? 
Or do i have to create an byte array which reads the stream until EOF and handle with the byte array?

      was (Author: olze84):
    ok i got it, thanks.
Is there any way to achieve the behavior i need, like converting the EofSensorInputStream to an IdentityInputStream?
  
> EofSensorInputStreams available() always returns 0
> --------------------------------------------------
>
>                 Key: HTTPCLIENT-1004
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1004
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient
>    Affects Versions: 4.1 Alpha2
>         Environment: win 7 x64, netbeans 6.9.1, jdk6_21
>            Reporter: oliver  z
>
> i just wrote a little mp3 audio player which retrieves a stream and plays it. 
> to make sure the user does not play further than the song has been stored into ram, i thought i just use the available() method from the class EofSensorInputStream.
> But this method always returns 0 (normal http connection), casting to a ByteArrayInputStream would be nice, but thats not working... so i took a look at the implementation of available():
> http://www.docjar.com/html/api/org/apache/http/conn/EofSensorInputStream.java.html
>   165       @Override
>   166       public int available() throws IOException {
>   167           int a = 0; // not -1
>   168   
>   169           if (isReadAllowed()) {
>   170               try {
>   171                   a = wrappedStream.available();
>   172                   // no checkEOF() here, available() can't trigger EOF
>   173               } catch (IOException ex) {
>   174                   checkAbort();
>   175                   throw ex;
>   176               }
>   177           }
>   178   
>   179           return a;
>   180       }
> wrappedStream is an InputStream, and InputStream says to available():
> The available method for class InputStream always returns 0. 
> This method should be overridden by subclasses. 
> Im not sure if this is a bug or a feature request
> Is there any other way how i can check how many bytes has been transfered into ram?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[jira] Commented: (HTTPCLIENT-1004) EofSensorInputStreams available() always returns 0

Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1004?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12916409#action_12916409 ] 

Oleg Kalnichevski commented on HTTPCLIENT-1004:
-----------------------------------------------

EofSensorInputStream is a wrapper class, which has no way of knowing how much data is buffered by the wrapped class other than delegating the call to the wrapped class. ContentLengthInputStream, ChunkedInputStream and IdentityInputStream classes in the 4.1 branch implement #available(). 

Are you sure you are using the latest 4.1 alpha and not 4.0.x?

Oleg

> EofSensorInputStreams available() always returns 0
> --------------------------------------------------
>
>                 Key: HTTPCLIENT-1004
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1004
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient
>    Affects Versions: 4.1 Alpha2
>         Environment: win 7 x64, netbeans 6.9.1, jdk6_21
>            Reporter: oliver  z
>
> i just wrote a little mp3 audio player which retrieves a stream and plays it. 
> to make sure the user does not play further than the song has been stored into ram, i thought i just use the available() method from the class EofSensorInputStream.
> But this method always returns 0 (normal http connection), casting to a ByteArrayInputStream would be nice, but thats not working... so i took a look at the implementation of available():
> http://www.docjar.com/html/api/org/apache/http/conn/EofSensorInputStream.java.html
>   165       @Override
>   166       public int available() throws IOException {
>   167           int a = 0; // not -1
>   168   
>   169           if (isReadAllowed()) {
>   170               try {
>   171                   a = wrappedStream.available();
>   172                   // no checkEOF() here, available() can't trigger EOF
>   173               } catch (IOException ex) {
>   174                   checkAbort();
>   175                   throw ex;
>   176               }
>   177           }
>   178   
>   179           return a;
>   180       }
> wrappedStream is an InputStream, and InputStream says to available():
> The available method for class InputStream always returns 0. 
> This method should be overridden by subclasses. 
> Im not sure if this is a bug or a feature request
> Is there any other way how i can check how many bytes has been transfered into ram?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[jira] Commented: (HTTPCLIENT-1004) EofSensorInputStreams available() always returns 0

Posted by "oliver z (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1004?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12916790#action_12916790 ] 

oliver  z commented on HTTPCLIENT-1004:
---------------------------------------

i tested it with a free online mp3:

HttpClient httpclient = new DefaultHttpClient();
        HttpGet httpget = new HttpGet("http://www.ravn.de/stuff/Programmierer.mp3");

        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            InputStream instream = entity.getContent();
            try {
                while (instream.read() != -1) {
                    System.out.println(instream.available());
                }
            } finally {
                instream.close();
            }
        }

looks pretty strange to me 
i'm not sure why in my application the output is always 0... any ideas?

> EofSensorInputStreams available() always returns 0
> --------------------------------------------------
>
>                 Key: HTTPCLIENT-1004
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1004
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient
>    Affects Versions: 4.1 Alpha2
>         Environment: win 7 x64, netbeans 6.9.1, jdk6_21
>            Reporter: oliver  z
>
> i just wrote a little mp3 audio player which retrieves a stream and plays it. 
> to make sure the user does not play further than the song has been stored into ram, i thought i just use the available() method from the class EofSensorInputStream.
> But this method always returns 0 (normal http connection), casting to a ByteArrayInputStream would be nice, but thats not working... so i took a look at the implementation of available():
> http://www.docjar.com/html/api/org/apache/http/conn/EofSensorInputStream.java.html
>   165       @Override
>   166       public int available() throws IOException {
>   167           int a = 0; // not -1
>   168   
>   169           if (isReadAllowed()) {
>   170               try {
>   171                   a = wrappedStream.available();
>   172                   // no checkEOF() here, available() can't trigger EOF
>   173               } catch (IOException ex) {
>   174                   checkAbort();
>   175                   throw ex;
>   176               }
>   177           }
>   178   
>   179           return a;
>   180       }
> wrappedStream is an InputStream, and InputStream says to available():
> The available method for class InputStream always returns 0. 
> This method should be overridden by subclasses. 
> Im not sure if this is a bug or a feature request
> Is there any other way how i can check how many bytes has been transfered into ram?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[jira] Issue Comment Edited: (HTTPCLIENT-1004) EofSensorInputStreams available() always returns 0

Posted by "oliver z (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1004?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12916790#action_12916790 ] 

oliver  z edited comment on HTTPCLIENT-1004 at 10/1/10 1:51 AM:
----------------------------------------------------------------

i tested it with a free online mp3:

HttpClient httpclient = new DefaultHttpClient();
        HttpGet httpget = new HttpGet("http://www.ravn.de/stuff/Programmierer.mp3");

        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            InputStream instream = entity.getContent();
            try {
                while (instream.read() != -1) {
                    System.out.println(instream.available());
                }
            } finally {
                instream.close();
            }
        }

looks pretty strange to me, because if the read() method is not there (eg. while(true)) the output is always 1451 and the count is not rising
i'm not sure why in my application the output is always 0... any ideas?

      was (Author: olze84):
    i tested it with a free online mp3:

HttpClient httpclient = new DefaultHttpClient();
        HttpGet httpget = new HttpGet("http://www.ravn.de/stuff/Programmierer.mp3");

        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            InputStream instream = entity.getContent();
            try {
                while (instream.read() != -1) {
                    System.out.println(instream.available());
                }
            } finally {
                instream.close();
            }
        }

looks pretty strange to me 
i'm not sure why in my application the output is always 0... any ideas?
  
> EofSensorInputStreams available() always returns 0
> --------------------------------------------------
>
>                 Key: HTTPCLIENT-1004
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1004
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient
>    Affects Versions: 4.1 Alpha2
>         Environment: win 7 x64, netbeans 6.9.1, jdk6_21
>            Reporter: oliver  z
>
> i just wrote a little mp3 audio player which retrieves a stream and plays it. 
> to make sure the user does not play further than the song has been stored into ram, i thought i just use the available() method from the class EofSensorInputStream.
> But this method always returns 0 (normal http connection), casting to a ByteArrayInputStream would be nice, but thats not working... so i took a look at the implementation of available():
> http://www.docjar.com/html/api/org/apache/http/conn/EofSensorInputStream.java.html
>   165       @Override
>   166       public int available() throws IOException {
>   167           int a = 0; // not -1
>   168   
>   169           if (isReadAllowed()) {
>   170               try {
>   171                   a = wrappedStream.available();
>   172                   // no checkEOF() here, available() can't trigger EOF
>   173               } catch (IOException ex) {
>   174                   checkAbort();
>   175                   throw ex;
>   176               }
>   177           }
>   178   
>   179           return a;
>   180       }
> wrappedStream is an InputStream, and InputStream says to available():
> The available method for class InputStream always returns 0. 
> This method should be overridden by subclasses. 
> Im not sure if this is a bug or a feature request
> Is there any other way how i can check how many bytes has been transfered into ram?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[jira] Commented: (HTTPCLIENT-1004) EofSensorInputStreams available() always returns 0

Posted by "oliver z (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1004?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12916550#action_12916550 ] 

oliver  z commented on HTTPCLIENT-1004:
---------------------------------------

i am using HtmlUnit 2.8. I replaced the old HttpClient/HttpCore/HttpMime jars with the new one (4.1alpha2 and 4.1-beta2) and recompiled it. So i think HtmlUnit is using the new one, not the 4.0 version.

I tried to cast the InputStream to ContentLengthInputStream but i still get

Exception in thread "Thread-28" java.lang.ClassCastException: org.apache.http.conn.EofSensorInputStream cannot be cast to org.apache.http.impl.io.ContentLengthInputStream
        at myPlay.player.PlayThread$SongSlider.run(PlayThread.java:56)

I will take a closer look on this on the weekend.

> EofSensorInputStreams available() always returns 0
> --------------------------------------------------
>
>                 Key: HTTPCLIENT-1004
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1004
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient
>    Affects Versions: 4.1 Alpha2
>         Environment: win 7 x64, netbeans 6.9.1, jdk6_21
>            Reporter: oliver  z
>
> i just wrote a little mp3 audio player which retrieves a stream and plays it. 
> to make sure the user does not play further than the song has been stored into ram, i thought i just use the available() method from the class EofSensorInputStream.
> But this method always returns 0 (normal http connection), casting to a ByteArrayInputStream would be nice, but thats not working... so i took a look at the implementation of available():
> http://www.docjar.com/html/api/org/apache/http/conn/EofSensorInputStream.java.html
>   165       @Override
>   166       public int available() throws IOException {
>   167           int a = 0; // not -1
>   168   
>   169           if (isReadAllowed()) {
>   170               try {
>   171                   a = wrappedStream.available();
>   172                   // no checkEOF() here, available() can't trigger EOF
>   173               } catch (IOException ex) {
>   174                   checkAbort();
>   175                   throw ex;
>   176               }
>   177           }
>   178   
>   179           return a;
>   180       }
> wrappedStream is an InputStream, and InputStream says to available():
> The available method for class InputStream always returns 0. 
> This method should be overridden by subclasses. 
> Im not sure if this is a bug or a feature request
> Is there any other way how i can check how many bytes has been transfered into ram?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[jira] Commented: (HTTPCLIENT-1004) EofSensorInputStreams available() always returns 0

Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1004?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12916570#action_12916570 ] 

Oleg Kalnichevski commented on HTTPCLIENT-1004:
-----------------------------------------------

Do not cast. Just call #available on that instance of InputStream. The call will be delegated to the wrapped input stream.

> i just saw that htmlunit uses DefaultHttpClient, could this be somehow the problem?

I do not think so.

Oleg

> EofSensorInputStreams available() always returns 0
> --------------------------------------------------
>
>                 Key: HTTPCLIENT-1004
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1004
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient
>    Affects Versions: 4.1 Alpha2
>         Environment: win 7 x64, netbeans 6.9.1, jdk6_21
>            Reporter: oliver  z
>
> i just wrote a little mp3 audio player which retrieves a stream and plays it. 
> to make sure the user does not play further than the song has been stored into ram, i thought i just use the available() method from the class EofSensorInputStream.
> But this method always returns 0 (normal http connection), casting to a ByteArrayInputStream would be nice, but thats not working... so i took a look at the implementation of available():
> http://www.docjar.com/html/api/org/apache/http/conn/EofSensorInputStream.java.html
>   165       @Override
>   166       public int available() throws IOException {
>   167           int a = 0; // not -1
>   168   
>   169           if (isReadAllowed()) {
>   170               try {
>   171                   a = wrappedStream.available();
>   172                   // no checkEOF() here, available() can't trigger EOF
>   173               } catch (IOException ex) {
>   174                   checkAbort();
>   175                   throw ex;
>   176               }
>   177           }
>   178   
>   179           return a;
>   180       }
> wrappedStream is an InputStream, and InputStream says to available():
> The available method for class InputStream always returns 0. 
> This method should be overridden by subclasses. 
> Im not sure if this is a bug or a feature request
> Is there any other way how i can check how many bytes has been transfered into ram?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[jira] Resolved: (HTTPCLIENT-1004) EofSensorInputStreams available() always returns 0

Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HTTPCLIENT-1004?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Oleg Kalnichevski resolved HTTPCLIENT-1004.
-------------------------------------------

    Resolution: Not A Problem

I ran this code with HttpCore 4.1-beta2 and HttpClient 4.0.3 and got 8191 bytes back

---
        DefaultHttpClient httpclient = new DefaultHttpClient();
        HttpGet httpget = new HttpGet("https://www.apache.org/");

        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            InputStream instream = entity.getContent();
            try {
                instream.read();
                System.out.println(instream.available());
            } finally {
                instream.close();
            }
        }

        httpclient.getConnectionManager().shutdown();
---

> EofSensorInputStreams available() always returns 0
> --------------------------------------------------
>
>                 Key: HTTPCLIENT-1004
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1004
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient
>    Affects Versions: 4.1 Alpha2
>         Environment: win 7 x64, netbeans 6.9.1, jdk6_21
>            Reporter: oliver  z
>
> i just wrote a little mp3 audio player which retrieves a stream and plays it. 
> to make sure the user does not play further than the song has been stored into ram, i thought i just use the available() method from the class EofSensorInputStream.
> But this method always returns 0 (normal http connection), casting to a ByteArrayInputStream would be nice, but thats not working... so i took a look at the implementation of available():
> http://www.docjar.com/html/api/org/apache/http/conn/EofSensorInputStream.java.html
>   165       @Override
>   166       public int available() throws IOException {
>   167           int a = 0; // not -1
>   168   
>   169           if (isReadAllowed()) {
>   170               try {
>   171                   a = wrappedStream.available();
>   172                   // no checkEOF() here, available() can't trigger EOF
>   173               } catch (IOException ex) {
>   174                   checkAbort();
>   175                   throw ex;
>   176               }
>   177           }
>   178   
>   179           return a;
>   180       }
> wrappedStream is an InputStream, and InputStream says to available():
> The available method for class InputStream always returns 0. 
> This method should be overridden by subclasses. 
> Im not sure if this is a bug or a feature request
> Is there any other way how i can check how many bytes has been transfered into ram?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[jira] Commented: (HTTPCLIENT-1004) EofSensorInputStreams available() always returns 0

Posted by "oliver z (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1004?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12916571#action_12916571 ] 

oliver  z commented on HTTPCLIENT-1004:
---------------------------------------

i tried, but it still returns 0 

> EofSensorInputStreams available() always returns 0
> --------------------------------------------------
>
>                 Key: HTTPCLIENT-1004
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1004
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient
>    Affects Versions: 4.1 Alpha2
>         Environment: win 7 x64, netbeans 6.9.1, jdk6_21
>            Reporter: oliver  z
>
> i just wrote a little mp3 audio player which retrieves a stream and plays it. 
> to make sure the user does not play further than the song has been stored into ram, i thought i just use the available() method from the class EofSensorInputStream.
> But this method always returns 0 (normal http connection), casting to a ByteArrayInputStream would be nice, but thats not working... so i took a look at the implementation of available():
> http://www.docjar.com/html/api/org/apache/http/conn/EofSensorInputStream.java.html
>   165       @Override
>   166       public int available() throws IOException {
>   167           int a = 0; // not -1
>   168   
>   169           if (isReadAllowed()) {
>   170               try {
>   171                   a = wrappedStream.available();
>   172                   // no checkEOF() here, available() can't trigger EOF
>   173               } catch (IOException ex) {
>   174                   checkAbort();
>   175                   throw ex;
>   176               }
>   177           }
>   178   
>   179           return a;
>   180       }
> wrappedStream is an InputStream, and InputStream says to available():
> The available method for class InputStream always returns 0. 
> This method should be overridden by subclasses. 
> Im not sure if this is a bug or a feature request
> Is there any other way how i can check how many bytes has been transfered into ram?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[jira] Commented: (HTTPCLIENT-1004) EofSensorInputStreams available() always returns 0

Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1004?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12916846#action_12916846 ] 

Oleg Kalnichevski commented on HTTPCLIENT-1004:
-----------------------------------------------

Oliver

I think your expectations are wrong. HttpClient does not maintain a read-ahead buffer. It reads a chunk of data into the session buffer and does not read more data from the underlying connection until the buffered data is fully consumed.

Oleg

> EofSensorInputStreams available() always returns 0
> --------------------------------------------------
>
>                 Key: HTTPCLIENT-1004
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1004
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient
>    Affects Versions: 4.1 Alpha2
>         Environment: win 7 x64, netbeans 6.9.1, jdk6_21
>            Reporter: oliver  z
>
> i just wrote a little mp3 audio player which retrieves a stream and plays it. 
> to make sure the user does not play further than the song has been stored into ram, i thought i just use the available() method from the class EofSensorInputStream.
> But this method always returns 0 (normal http connection), casting to a ByteArrayInputStream would be nice, but thats not working... so i took a look at the implementation of available():
> http://www.docjar.com/html/api/org/apache/http/conn/EofSensorInputStream.java.html
>   165       @Override
>   166       public int available() throws IOException {
>   167           int a = 0; // not -1
>   168   
>   169           if (isReadAllowed()) {
>   170               try {
>   171                   a = wrappedStream.available();
>   172                   // no checkEOF() here, available() can't trigger EOF
>   173               } catch (IOException ex) {
>   174                   checkAbort();
>   175                   throw ex;
>   176               }
>   177           }
>   178   
>   179           return a;
>   180       }
> wrappedStream is an InputStream, and InputStream says to available():
> The available method for class InputStream always returns 0. 
> This method should be overridden by subclasses. 
> Im not sure if this is a bug or a feature request
> Is there any other way how i can check how many bytes has been transfered into ram?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[jira] Issue Comment Edited: (HTTPCLIENT-1004) EofSensorInputStreams available() always returns 0

Posted by "oliver z (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1004?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12916571#action_12916571 ] 

oliver  z edited comment on HTTPCLIENT-1004 at 9/30/10 1:53 PM:
----------------------------------------------------------------

i tried, but it still returns 0 

just downloaded the sources of httpclient and httpcore - same behavior :(


getting stream...
1452    <--- i haven seen this before 
0
0
0

thats how i get the InputStream:
            HttpWebConnection conn = (HttpWebConnection) getWebConnection();
            HttpResponse response = conn.httpClient_.execute(getStreamPost);

            contentLength = response.getEntity().getContentLength();
            song.setContentLength(contentLength);
            is = response.getEntity().getContent();

which i pass now to my play/slider method:
private static class SongSlider extends Thread {

        private static InputStream stream;

        public SongSlider(InputStream stream) {
            SongSlider.stream = stream;
        }

        @Override
        public void run() {
            while (true) {
                try {
                    try {
                        //Playlist.jSlider1.setIrgendwas(stream.available());
                        System.out.println(stream.available());
                    } catch (IOException ex) {
                        Logger.getLogger(PlayThread.class.getName()).log(Level.SEVERE, null, ex);
                    }                 
                    sleep(100);
                } catch (InterruptedException ex) {
                    Thread.currentThread().interrupt();
                }
            }
        }
    }



      was (Author: olze84):
    i tried, but it still returns 0 
  
> EofSensorInputStreams available() always returns 0
> --------------------------------------------------
>
>                 Key: HTTPCLIENT-1004
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1004
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient
>    Affects Versions: 4.1 Alpha2
>         Environment: win 7 x64, netbeans 6.9.1, jdk6_21
>            Reporter: oliver  z
>
> i just wrote a little mp3 audio player which retrieves a stream and plays it. 
> to make sure the user does not play further than the song has been stored into ram, i thought i just use the available() method from the class EofSensorInputStream.
> But this method always returns 0 (normal http connection), casting to a ByteArrayInputStream would be nice, but thats not working... so i took a look at the implementation of available():
> http://www.docjar.com/html/api/org/apache/http/conn/EofSensorInputStream.java.html
>   165       @Override
>   166       public int available() throws IOException {
>   167           int a = 0; // not -1
>   168   
>   169           if (isReadAllowed()) {
>   170               try {
>   171                   a = wrappedStream.available();
>   172                   // no checkEOF() here, available() can't trigger EOF
>   173               } catch (IOException ex) {
>   174                   checkAbort();
>   175                   throw ex;
>   176               }
>   177           }
>   178   
>   179           return a;
>   180       }
> wrappedStream is an InputStream, and InputStream says to available():
> The available method for class InputStream always returns 0. 
> This method should be overridden by subclasses. 
> Im not sure if this is a bug or a feature request
> Is there any other way how i can check how many bytes has been transfered into ram?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[jira] Commented: (HTTPCLIENT-1004) EofSensorInputStreams available() always returns 0

Posted by "oliver z (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1004?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12917289#action_12917289 ] 

oliver  z commented on HTTPCLIENT-1004:
---------------------------------------

ok i got it, thanks.
Is there any way to achieve the behavior i need, like converting the EofSensorInputStream to an IdentityInputStream?

> EofSensorInputStreams available() always returns 0
> --------------------------------------------------
>
>                 Key: HTTPCLIENT-1004
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1004
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient
>    Affects Versions: 4.1 Alpha2
>         Environment: win 7 x64, netbeans 6.9.1, jdk6_21
>            Reporter: oliver  z
>
> i just wrote a little mp3 audio player which retrieves a stream and plays it. 
> to make sure the user does not play further than the song has been stored into ram, i thought i just use the available() method from the class EofSensorInputStream.
> But this method always returns 0 (normal http connection), casting to a ByteArrayInputStream would be nice, but thats not working... so i took a look at the implementation of available():
> http://www.docjar.com/html/api/org/apache/http/conn/EofSensorInputStream.java.html
>   165       @Override
>   166       public int available() throws IOException {
>   167           int a = 0; // not -1
>   168   
>   169           if (isReadAllowed()) {
>   170               try {
>   171                   a = wrappedStream.available();
>   172                   // no checkEOF() here, available() can't trigger EOF
>   173               } catch (IOException ex) {
>   174                   checkAbort();
>   175                   throw ex;
>   176               }
>   177           }
>   178   
>   179           return a;
>   180       }
> wrappedStream is an InputStream, and InputStream says to available():
> The available method for class InputStream always returns 0. 
> This method should be overridden by subclasses. 
> Im not sure if this is a bug or a feature request
> Is there any other way how i can check how many bytes has been transfered into ram?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org