Results 1 to 10 of 10
- 04-14-2012, 02:10 AM #1
Member
- Join Date
- Apr 2012
- Posts
- 6
- Rep Power
- 0
Who did the job for the InputStream
As we know, the Java API has an abstract class InputStream. It provide a abstract method int read(). The other methods in the InputStream rely on this method to read a byte from the outer stream.
Since the method doesn't provide any implementation, neither by this child class, for instance FileInputStream.
Who did the job for InputStream?
How can I learn about this information.
Thanks!
- 04-14-2012, 02:42 AM #2
Re: Who did the job for the InputStream
The source for many of the java classes is in the JDK in a zip file. You could look there.
If you don't understand my response, don't ignore it, ask a question.
- 04-14-2012, 03:34 AM #3
Member
- Join Date
- Apr 2012
- Posts
- 6
- Rep Power
- 0
- 04-14-2012, 03:55 AM #4
Re: Who did the job for the InputStream
Have you installed the JDK? Search in its folders for a zip file. One of them has the source for many of the java classes.
If you don't understand my response, don't ignore it, ask a question.
- 04-14-2012, 04:09 AM #5
Member
- Join Date
- Apr 2012
- Posts
- 6
- Rep Power
- 0
Re: Who did the job for the InputStream
Let I say, I read the source code InputStream.java and FileInputStream.java
That's why I have this question.
I am not sure whether you ask me to read the source code or rather than other Zip file.
- 04-14-2012, 04:34 AM #6
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
Re: Who did the job for the InputStream
FileInputStream *does* provide an implementation for the abstract method kinda/sorta:As we know, the Java API has an abstract class InputStream. It provide a abstract method int read(). The other methods in the InputStream rely on this method to read a byte from the outer stream.
Since the method doesn't provide any implementation, neither by this child class, for instance FileInputStream.
It declares the method to be native. (See, eg this old JavaWorld article.)Java Code:/** * Reads a byte of data from this input stream. This method blocks * if no input is yet available. * * @return the next byte of data, or <code>-1</code> if the end of the * file is reached. * @exception IOException if an I/O error occurs. */ public native int read() throws IOException;
As for what (native) library is being used: I don't know, but you should be able to find out from the java code what libraries it loads. (Nothing from within FileInputStream.java itself, by the looks of things.) As for the native source code for these libraries you might try somewhere like OpenJDK: JDK 6 - I am pretty sure the code is (or was) available under the Java Research License.
- 04-14-2012, 04:54 AM #7
Member
- Join Date
- Apr 2012
- Posts
- 6
- Rep Power
- 0
Re: Who did the job for the InputStream
Oh,Thanks! I guess it should be what I am looking for.
- 04-14-2012, 04:08 PM #8
Member
- Join Date
- Apr 2012
- Posts
- 6
- Rep Power
- 0
Re: Who did the job for the InputStream
I review this guide
http://java.sun.com/docs/books/jni/download/jni.pdf
It is very helpful to understand the JNI, although I also don't where the Java API calls the library yet.
Now I rise another confusion. I thought the output should work like the input one, but it seems not the same case
for instance,we all know
System.out.print(int b) can output the bytes, The System has a static field "out" is a PrintStream. It implements the print(int b)
but the print(int b) calls the write(b). PrintStream calls the write(int b) from its parent FilterOutputStream, so I guess the write(int b) should be implemented in FilterOutputStream, but it doesn't!
public FilterOutputStream(OutputStream out) {
this.out = out;
}
public void write(int b) throws IOException {
out.write(b);
}
Did I miss anything again? Thanks!
- 04-14-2012, 06:18 PM #9
Member
- Join Date
- Apr 2012
- Posts
- 6
- Rep Power
- 0
Re: Who did the job for the InputStream
After reading the System.java code carefully, I found that the System.out is a special one.
The FileOutputStream is similar to the FileInoutStream, you will the final one is a native one.
But the System.out doesn't directly use the native one, I guess it uses some initial jvm action to do this thing.
- 04-15-2012, 03:05 AM #10
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
Re: Who did the job for the InputStream
Yes - I was going to refer you to something that described the JNI. When I looked at FileOutputStream - as I mentioned - I couldn't see which native library was involved. Perhaps you could check the classes mentioned in that class's fields and constructors.I review this guide
http://java.sun.com/docs/books/jni/download/jni.pdf
It is very helpful to understand the JNI, although I also don't where the Java API calls the library yet.
This is quite common. PrintStream calls a method on its OutputStream field and that one (?) is the native one. In general you have the "chase" a Java method back to find its native origins. I suppose (but I'm no expert) that *every* method is like this: look far enough back and you will find a library (.dll, .so or whatever) that does the right thing for the operating system it is designed for.But the System.out doesn't directly use the native one
Similar Threads
-
InputStream and BufferedInputStream
By dalu in forum New To JavaReplies: 2Last Post: 10-21-2011, 02:29 PM -
Creating an InputStream
By c26354 in forum New To JavaReplies: 10Last Post: 07-12-2011, 04:48 AM -
Problem with InputStream
By hedonist in forum New To JavaReplies: 7Last Post: 11-19-2010, 04:09 PM -
InputStream problem
By javabarn in forum New To JavaReplies: 10Last Post: 06-29-2010, 04:09 PM -
Java InputStream
By Bill88 in forum New To JavaReplies: 10Last Post: 09-21-2009, 02:40 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks