How do I provide implementaion for read() method of InputStream?
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   amit_parnerkar
Posted On:   Thursday, September 5, 2002 05:08 PM


I'm writing my own UserInputStream class which is inheriting from java.io.InputStream abstract class. This class has only one abstract mehod abstract int read()
How to provide implementation for this method?

Re: How do I provide implementaion for read() method of InputStream?

Posted By:   Stephen_Ostermiller  
Posted On:   Monday, September 16, 2002 12:36 PM

read() should return the next byte from your data source.
So if you were implementing a ByteArrayInputStream, your read() function would look something like this:


private int pos = 0;
private byte[] byteArray;

public ByteArrayInputStream(byte[] bytes){
byteArray = bytes;
}

public int read(){
if (pos >= byteArray.length) return -1;
return byteArray[pos++];
}

Re: How do I provide implementaion for read() method of InputStream?

Posted By:   eimi_nos  
Posted On:   Friday, September 6, 2002 12:14 AM

If you would not like to supply a particular implementation for this abstract method, you can leave implementation blank in this manner:

public int read(){;}
About | Sitemap | Contact