Results 1 to 14 of 14
Thread: Help with Readable Interface
- 02-04-2012, 07:48 AM #1
Senior Member
- Join Date
- Nov 2011
- Location
- Turkey
- Posts
- 378
- Blog Entries
- 24
- Rep Power
- 2
Help with Readable Interface
Output: NojasJava Code:package myPackage; import java.io.IOException; import java.nio.CharBuffer; import java.util.Scanner; public class RandomWords implements Readable { private static final char[] capitals = "JASON".toCharArray(); private int count; public RandomWords(int count) { this.count = count; } @Override public int read(CharBuffer cb) throws IOException { count = count-1; cb.append(capitals[count]); if(count == 0) return -1; return 0; } public static void main(String[] args) { Scanner s = new Scanner(new RandomWords(5)); while(s.hasNext()) System.out.println(s.next()); } }
Hi everyone,
My question is:
Can someone please tell me when the read() method is called ?
Can you also help with the charbuffer cb ? When is it created ? I do not see anyone creating a charbuffer cb here but it is used ?
Thanks.
- 02-04-2012, 07:56 AM #2
Re: Help with Readable Interface
Read the source of Scanner.java and you'll be able to find it.
-- see what the constructor does with the Readable argument
-- see how it is used and when/where its read(...) method is called.
-- see where the CharBuffer comes from
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 02-04-2012, 07:59 AM #3
Senior Member
- Join Date
- Nov 2011
- Location
- Turkey
- Posts
- 378
- Blog Entries
- 24
- Rep Power
- 2
Re: Help with Readable Interface
This is all I can find and it does not answer my questions:
A scanner can read text from any object which implements the Readable interface. If an invocation of the underlying readable's Readable.read(java.nio.CharBuffer) method throws an IOException then the scanner assumes that the end of the input has been reached. The most recent IOException thrown by the underlying readable can be retrieved via the ioException() method.
- 02-04-2012, 09:26 AM #4
Re: Help with Readable Interface
Read the source, not the API. You'll find the sources in src.zip in your JDK installation folder.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 02-04-2012, 10:11 AM #5
Senior Member
- Join Date
- Nov 2011
- Location
- Turkey
- Posts
- 378
- Blog Entries
- 24
- Rep Power
- 2
Re: Help with Readable Interface
In the jdk folder I only see a folder named api
- 02-04-2012, 02:17 PM #6
Re: Help with Readable Interface
You're looking in the wrong folder. The JDK installation folder has about 5 or 6 folders and 7 or 8 files, none of which is named "api"
Search your computer for "src.zip"
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 02-04-2012, 02:56 PM #7
Senior Member
- Join Date
- Nov 2011
- Location
- Turkey
- Posts
- 378
- Blog Entries
- 24
- Rep Power
- 2
Re: Help with Readable Interface
I definetly do not have that file. :(
-
Re: Help with Readable Interface
I didn't get the source for 1.7 either with my download, but I know that you can get the source for Java 1.6 here:
Java SE Downloads
Search for "Java SE 6 JDK Source Code" on this page.
- 02-04-2012, 06:56 PM #9
Re: Help with Readable Interface
Sorry about that, and thanks for the info.
Oracle claims the src.zip ships with JDK7
JDK File Structure
There's an alternative download here:
jdk7src – Alternative to JDK src.zip with all publicly available source files
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 02-04-2012, 08:08 PM #10
Senior Member
- Join Date
- Nov 2011
- Location
- Turkey
- Posts
- 378
- Blog Entries
- 24
- Rep Power
- 2
Re: Help with Readable Interface
Ok I found the Scanner.java in src-jdk.zip and opened it with notepad but it is impossible to read this.
Am I trying to read something wrong ?
- 02-04-2012, 08:15 PM #11
Re: Help with Readable Interface
Notepad doesn't correctly render newlines without carriage returns (\n without \r). Use a decent text or code editor.
What IDE do you use?
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 02-04-2012, 08:27 PM #12
Senior Member
- Join Date
- Nov 2011
- Location
- Turkey
- Posts
- 378
- Blog Entries
- 24
- Rep Power
- 2
Re: Help with Readable Interface
Eclipse
- 02-05-2012, 06:57 AM #13
Re: Help with Readable Interface
Try opening the source in Eclipse's code editor then.
I use NetBeans, which can open files, in read-only mode, directly from a zip archive without the need to extract the files first. Maybe Eclipse has something like that -- wait for Fubarable or one of the Eclipse users to happen by.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 02-06-2012, 08:15 PM #14
Senior Member
- Join Date
- Nov 2011
- Location
- Turkey
- Posts
- 378
- Blog Entries
- 24
- Rep Power
- 2
Re: Help with Readable Interface
Is this the Javadoc mentioned here?
This here:
Scanner (Java Platform SE 6)
Similar Threads
-
Document Directory does not exist or is not readable
By dpfister in forum LuceneReplies: 2Last Post: 03-15-2011, 08:45 AM -
Make a readable book for mobile phones?
By xmenus in forum CLDC and MIDPReplies: 0Last Post: 06-11-2010, 06:12 PM -
Readable Serialization
By falven in forum Advanced JavaReplies: 3Last Post: 05-31-2010, 01:57 AM -
ObjectInputStream wait for readable objects
By Singing Boyo in forum New To JavaReplies: 2Last Post: 06-08-2009, 03:43 AM -
Convertin a .DAT file into readable format
By janakiram.attuluri in forum Advanced JavaReplies: 1Last Post: 12-07-2007, 10:00 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks