How to user bufferedreader.read(char[] cbuf,int off,int len)

how to user bufferedreader.read(char[] cbuf,int off,int len)?
can you give me an sample code? i dont understand the use of offset here... thanks!

The offset simply gives you the ability to read in data starting at some point in the buffer other than the first character.
If, for example, you are reading from some stream that is being filled slower than you are reading, then you can write a read loop that will fill the buffer with successive reads - the first at character 0, then next offset past the end of the first set of data, etc.

Similar Messages

  • Need official interpretation - java.io.Reader read(char[] cbuf) method

    Hello Everyone,
    I need Sun API's official interpretation on java.io.Reader read(char[] cbuf) method;
    Say, I provide this read method a char[] of size 8096, could the implementing class return even before reading into the whole buffer array? Say, the implementing class just reads 1024 chars and return 1024 as the method output, has the implementing class fulfilled its obligation?
    In my mind, the read method should attempt to read and fill the buffer array until of course i/o error occurs or end of stream is reached? See BufferedReader source for this type of implementation.
    Or could the read method just attempt to read into the buffer (with no obligation) and can return before completely filling the buffer?
    Sincere Regards.

    This is the situation: (and we are caught in between arbitrating on whom to ask to make the fix)
    Please note that I am not taking any names here, but remember these vendors are the biggest in their market.
    Vendor Db A has an API wherein it returns a stream and its length;
    Vendor B consumers this API via the java.io.Reader class as follows:
    char[] data = new char[(int) VendorAStream.length()];
    VendorAStream.read(data);
    Vendor B contends that per java.io.Reader API, it is responsibility of Vendor A to implement the read method correctly!!! (which is to read the data completely, not partially); Vendor B further contends that their code works fine with all the other Db vendors (except Vendor A); [Quite *tupid reasoning in my mind ;-) ]
    Vendor A says per java API, we can partially fill the buffer (they are specifically only reading 1024 chars from the stream)
    Initially, I thought, Vendor B must fix the code to handle partial reads. But no where it is mentioned clearly that Reader.read only attempts to read the chars and can return before filling the buffer.
    Dannyyates,
    (*My interpretation*) The reason it says "*maximum* number of characters to read" is for the situation when end of stream is reached before fully filling the buffer. In that case, the length of buffer and number of actually chars read wont match. This explanation covers for your observation (c)
    BIJ001, No problem in your explanation. I understand and I am merely pointing you to alternate interpretation of the API.
    Please comment. Thanks for your time to discuss this.
    Sincere Regards.

  • InputStreamRead read(char[] cbuf, int offset, int length) method hangs

    This method hangs for the following values
    read(xchar, 0, 1)
    Does not throw any exception.
    The inputstream does have data in it.
    the characterset is cp037.

    So the problem is probably in your implementation of InputStream. Do you implement the available() method? What will your class do if you attempt to read more bytes than there are? (say, call read(chars, 0, 1000000))
    The InputStreamReader keeps an internal buffer (of 1024 bytes?) which it uses for decoding the bytesto characters..if your stream blocks when InputStreamReader is filling its buffer you'd get this sort of behaviour.

  • InputStreamReader read(char[] cbuf, int offset, int length) method hangs

    Hi all,
    I am posting this message again.
    I would appreciate any help, as I am stuck with a customer issue.
    This method hangs for the following values
    read(xchar, 0, 1)
    Does not throw any exception.
    The inputstream does have data in it.
    the characterset is cp037.
    I know for sure that the InputStream has data in it. In fact the read method reads couple of fields with length greater than 1 and hangs when it tries to read data with length 1.
    Bug # 4401798 talks about some error similar to this being fixed. Any one has any idea, which jdk had this problem and which one has a fix for this?
    Thanks.

    You should have continued in your original thread, rather than starting a new one. What you have posted in this new thread could have gone in the old one:
    http://forum.java.sun.com/thread.jspa?threadID=665303

  • BufferedReader.read blocks when wrapping InflaterInputStream

    Hello,
    I'm currently doing client - server communication using http chunked transfer encoding. Furthermore chunks sent are compressed using zlib in sync_flush mode. The client code reads data from an InputStream using the following code snippet:
    URLConnection conn = new URL(anUrl).openConnection();
    BufferedReader reader = new BufferedReader(new InputStreamReader(new InflaterInputStream(conn.getInputStream())));
    int read = 0;
    while ((read = reader.read()) != -1)
      System.out.println((char)read);When running the above code snippet, the client will not read on a per chunk basis, but will block until receiving EOF from server. When using BufferedInputStream instead everything works fine.
    Does anybody know how to overcome this problem?
    Thanks!

    Yes you are right!
    But as i said, using BufferInputStream instead gives an important different behaviour. In this case read doesn't block until the underlying stream receives EOF. The call to read will immediately return bytes when on the server side a chunk of data has been send to the output stream.
    When investigating why BufferedReader blocks, i found that StreamDecoder, a class member of InputStreamReader uses the following code to implement reading from the underlying InflaterInputStream.
      301       int implRead(char[] cbuf, int off, int end) throws IOException {
      315           for (;;) {
      316           CoderResult cr = decoder.decode(bb, cb, eof);
      317           if (cr.isUnderflow()) {
      318               if (eof)
      319                   break;
      320               if (!cb.hasRemaining())
      321                   break;
      322               if ((cb.position() > 0) && !inReady())
      323                   break;          // Block at most once
      324               int n = readBytes();
      325               if (n < 0) {
      326                   eof = true;
      327                   if ((cb.position() == 0) && (!bb.hasRemaining()))
      328                       break;
      329                   decoder.reset();
      330               }
      331               continue;
      332           }
      ...The part that will prevent BufferedReader from not blocking is "!inReady()" at line 322. This method calls, among other things, available on the underlying InflaterInputStream. But as stated there, InflaterInputStream will always return 1 until EOF and "Programs should not count on this method to return the actual number of bytes that could be read without blocking".
    So in my opinion StreamDecoder's implementation won't be able to handle chunked encoding "out of the box".

  • Users with read access to the site unable to view Managed Metadata Navigation

    Hi everyone,
    I created a Managed Metadata service and created group, term-set and terms
    I gave read access to users
    I set up navigation to use Managed Navigation
    I am logged in as farm admin and able to view the navigation when i browse site. But user are not seeing navigation.
    One thing i noticed is when i give users full access or designer access to site they will be able to see the navigation. but i don't want to give users full access or designer access to the site.
    How can users with read only access to site can view Managed Metadata Navigation...Please help?

    Hi Sunil,
    Have you given your users permissions to actually read the MMS data from the service application?
    http://technet.microsoft.com/en-us/library/ff625176.aspx covers permissions on the MMS.
    Regards
    Paul.
    <<edit>> On reflection you might be hitting the issue in this Stackexchange post..
    http://sharepoint.stackexchange.com/questions/75636/permissions-and-managed-metadata-in-navigation Is yours behaving the same way?
    Please ensure that you mark a question as Answered once you receive a satisfactory response. This helps people in future when searching and helps prevent the same questions being asked multiple times.

  • How many users/programs can access a cFP or cRIO channel set

    I have used cFP and regular FP for years, but just found a method to gather data from the units without FTP or accessing the flash drives.  My question is this, using a FP read VI, or cRIO read VI, how many users can read that data before the cFP or cRIO crash?  Can I access that data without influencing the embedded program? 
    Thanks,
    Bill

    Hey Bill.
    If the data is being sent to shared variables there shouldn't be a limit to the number of "users" or "programs" that can access the data from the shared variables.
    Regards,
    Claire Reid
    National Instruments

  • How to skip the '\n' char when reading with BufferedReader

    Hello to all the comunity that is at these forums, ;)
    I'm a venezuelan IT student, and as many arround here, I'm looking for some help with this homework...
    well the thing is that I need to read from the System.in untill I get the "" String. Well the initial idea was to make a BufferedReader object and put the br.readLine(); method inside a recursive method, like this:
       import java.io.*;
        public class P1_diccionary {
          String[] diccionario;
          int cont=0;
           void llenarDiccionario(String linea, String[] auxi)throws IOException{
             if(linea.compareTo("")!=0){
                 int aux = cont++;
                 diccionario = new String[cont];
                 for(int i=0;i<auxi.length;i++)
                     diccionario=auxi[i];
    diccionario[aux]=linea;
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    llenarDiccionario(reader.readLine(),diccionario);
    well, I think this one it's a nice idea, however, it doesn't work for me because the input is going to be just like this:
    word1: concept1...
    word2: concept2...
    word3: concept3...
    word4: concept4...
    and! it's going to be pasted on the console (that is "ctrl+c" then "ctrl+v")... that's the real problem that I have, the method that I did reads some lines not all of them, I think it's because there is no synchronization (guessing) between the ctrl+v and the execution of the program...
    so I thought about skiping the '\n' char, to do this I checked the readLine() method of the BufferedReader and found out that it calls a
    readLine(boolean ignoreLF)method and that ignoreLF and skipLF -boolean form the class- determine whether readLine() will skip the '\n' char or not:
    boolean omitLF = ignoreLF || skipLF;ok now the question: how do I make ignoreLF or skipLF = true? I tried to look more in the BufferedReader class but I didn't see how to change the skipLF value...
    well guess that's all, I'll really apriciate all of your help, and any other ideas that you might have to solve the problem...
    well thanks to everybody and see ya ;)

    Use read() instead of readLine(). This method will read characters, and does not treat the EOL charactger the same way. Just keep reading until you find a sequence of characters (two EOL sequences in a row) that matches your end condition. Just be careful, since different OSs have different EOL sequences ... \n, \n\r, or \r. Also, remember that you will have to deal with the EOL sequences. They will not be discarded automatically.
    You can also use read( char[], int, int) to read as many characters as you want, without regard to EOL sequences. This will only stop reading when EOF is reached, or when the next read will cause the underlying stream to block, or when you have read a specified number of characters. Again, this will not terminate at a EOL sequence, and will include the EOL sequences in your array.
    As far as readLine() is concerned, I think you want to stop when you have TWO successive reads that equal "".
    � {�                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How to read char from console

    Hi can any body help me..
    I want to read char from keybord. withought pressing ENTER.
    I am not sure how i can do it. I can't use
    BufferedReader br = new  BufferedReader(new InputStreamReader ( System.in )) ;
    char key ;
    key = (char )br.read() ;
    cuz i have to press ENTER every time to read char.
    Thanks in advance.

    try this,I' have found a part on Internet
    package exercises;
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    * questa � la classe d' esempio per leggere l'input dalla console*/
    public class Echo {
    public static void main(String args[]) throws Exception{
    // This is where the magic happens. We have a plain old InputStream
    // and we want to read lines of text from the console.
    // To read lines of text we need a BufferedReader but the BufferedReader
    // only takes Readers as parameters.
    // InputStreamReader adapts the API of Streams to the API of Readers;
    // receives a Stream and creates a Reader, perfect for our purposes.
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String input = "";
    while(true){
    System.out.print("ECHO< ");
    //As easy as that. Just readline, and receive a string with
    //the LF/CR stripped away.
    input = in.readLine();
    //Is a faster alternative to: if (input == null || input.equals(""))
    //The implementation of equals method inside String checks for
    // nulls before making any reference to the object.
    // Also the operator instance of returns false if the left-hand operand is null
    if ("".equals(input)){
    break;
    }else
    // Here you place your command pattern code.
    if ("ok".equals(input)){
    System.out.println("OK command received: do something �");
    //Output in uppercase
    System.out.println("ECHO> " + input.toUpperCase());
    System.out.println("ECHO> bye bye");
    //We exit without closing the Reader, since is standard input,
    // you shouldn't try to do it.
    // For all other streams remember to close before exit.
    }

  • How to find from the data dict if a user has read access on a directory

    How to find "dynamically" if a user has READ access to a directory object.
    I want to know if there is a data dictionary table that holds if a user/schema has read access to a directory object.
    I know there is an dba_directories table and an all_directories table but they dont give information as to which user has read access granted to the directory.

    Not so difficult.
    select  'YES'
       from all_tab_privs A, all_directories B
       where a.grantee = 'USERNAME'
           and a.table_name = b.directory_name
           and b.directory_path = 'PATH YOU ARE LOOKING FOR'
    How to find "dynamically" if a user has READ access to a directory object.
    I want to know if there is a data dictionary table that holds if a user/schema has read access to a directory object.
    I know there is an dba_directories table and an all_directories table but they dont give information as to which user has read access granted to the directory.

  • How to make a reading implausible in user define validations?

    Hi all,
    Can any1 tell me how to make a reading implausible
    in user define validations.
    Regards,
    Darshana.

    I don't have an example at hand right now, but I've done this in the past.
    If my memory doesn't fail me, one of the return parameters of the user-exit in which you have to make your validations has a parameter that let's you define (im)plausibility.
    Edit: the user exit has:
    EXCEPTIONS
           PLAUSI_ERROR
    So, raise this exception to get an implausible reading.
    Hope this helps!
    Kevin
    Edited by: Kevin De Wilde on Jul 8, 2008 11:09 AM

  • How to create fillable forms for users of reader IX or X in acrobat pro XI?

    I created fillable forms in Acrobat Pro XI. How can i make them fillable also for users with Reader IX or X? As Adobe Reader für Vista or Linux is only available in version IX or X, it is not possible for these users to fill in the forms?

    Open PDF Form in Acrobat XI then choose File > Save As Other > Reader Extended PDF > Enable More Tools (inclues form fill-in & save)...
    Then, save the form with new name and it's gonna work.
    Message was edited by: Anoop9178
    Edited the option.

  • BufferedReader cant read char

    The reader object below is a BufferedReader and I initialized it like this
                                                                   String fileName = "abc.txt"
                   FileReader fr = new FileReader(fileName);
                   BufferedReader reader = new BufferedReader(fr);The code below throws exception null... I dont know why .....
    try{
                   String s;
                   int charValue;
                                                             System.out.println("******"); //PRINTS THIS
                                                                while ((charValue = reader.read()) != -1)// HERE IT THROWS                                                       {
                        System.out.println("--"); // DOESNT PRINT
                        boolean streamReady = reader.ready();
                        System.out.println(streamReady);
                        s=reader.readLine();
                        System.out.println(s);
                   }//try
                   catch(EOFException e){System.out.println("EOF excption");}
                   catch(IOException e){System.out.println("IO exception");}
                   catch(Exception e){System.out.println("Exception "+e.getMessage());}

    Okay... e.printStackTrace worked.....
    It gives
    java.lang.NullPointerException
    at LanguageRecognizer.getTransitionTable(LanguageRecognizer.java:59)
    at LanguageRecognizer.promptUser(LanguageRecognizer.java:44)
    at LanguageRecognizer.getFileName(LanguageRecognizer.java:23)
    at Menu.show(Menu.java:42)
    at RecognizerLauncher.main(RecognizerLauncher.java:6)
    Its giving errors where I am calling other methods like for example:
    I am calling from
    public void promptUser()
    {//blah blah
    getTransitionTable(); // HERE
    }

  • How to create a user with read only access for ESB / BPEL Console

    I need to create a user with read only access to ESB Console & BPEL Console. I have created a user
    (esbreadonly) and assigned ascontrol_monitor role but user is still able to
    delete services from ESB systems (such as DefaultSystem). Is there any way to
    create a user that has strickly read only access to ESB Console & BPEL
    Console
    Thanks
    Dinesh Patel

    Check out this post.. I'm in the process of testing.
    http://chintanblog.blogspot.com/2007/12/i-saw-numerous-people-asking-about-bpel_290.html

  • How can I input read a line from a file and output it into the screen?

    How can I input read a line from a file and output it into the screen?
    If I have a file contains html code and I only want the URL, for example, www24.brinkster.com how can I read that into the buffer and write the output into the screen that using Java?
    Any help will be appreciate!
    ======START FILE default.html ========
    <html>
    <body>
    <br><br>
    <center>
    <font size=4 face=arial color=#336699>
    <b>Welcome to a DerekTran's Website!</b><br>
    Underconstructions.... <br>
    </font> </center>
    <font size=3 face=arial color=black> <br>
    Hello,<br>
    <br>
    I've been using the PWS to run the website on NT workstation 4.0. It was working
    fine. <br>
    The URL should be as below: <br>
    http://127.0.0.1/index.htm or http://localhost/index.htm
    <p>And suddently, it stops working, it can't find the connection. I tried to figure
    out what's going on, but still <font color="#FF0000">NO CLUES</font>. Does anyone
    know what's going on? Please see the link for more.... I believe that I setup
    everything correctly and the bugs still flying in the server.... <br>
    Thank you for your help.</P>
    </font>
    <p><font size=3 face=arial color=black>PeerWebServer.doc
    <br>
    <p><font size=3 face=arial color=black>CannotFindServer.doc
    <br>
    <p><font size=3 face=arial color=black>HOSTS file is not found
    <br>
    <p><font size=3 face=arial color=black>LMHOSTS file
    <br>
    <p><font size=3 face=arial color=black>How to Setup PWS on NT
    <BR>
    <p><font size=3 face=arial color=black>Issdmin doc</BR>
    Please be patient while the document is download....</font>
    <font size=3 face=arial color=black><br>If you have any ideas please drop me a
    few words at [email protected] </font><br>
    <br>
    <br>
    </p>
    <p><!--#include file="Hits.asp"--> </p>
    </body>
    </html>
    ========= END OF FILE ===============

    Hi!
    This is a possible solution to your problem.
    import java.io.*;
    class AddressExtractor {
         public static void main(String args[]) throws IOException{
              //retrieve the commandline parameters
              String fileName = "default.html";
              if (args.length != 0)      fileName =args[0];
               else {
                   System.out.println("Usage : java AddressExtractor <htmlfile>");
                   System.exit(0);
              BufferedReader in = new BufferedReader(new FileReader(new File(fileName)));
              StreamTokenizer st = new StreamTokenizer(in);
              st.lowerCaseMode(true);
              st.wordChars('/','/'); //include '/' chars as part of token
              st.wordChars(':',':'); //include ':' chars as part of token
              st.quoteChar('\"'); //set the " quote char
              int i;
              while (st.ttype != StreamTokenizer.TT_EOF) {
                   i = st.nextToken();
                   if (st.ttype == StreamTokenizer.TT_WORD) {          
                        if (st.sval.equals("href")) {               
                             i = st.nextToken(); //the next token (assumed) is the  '=' sign
                             i = st.nextToken(); //then after it is the href value.               
                             getURL(st.sval); //retrieve address
              in.close();
         static void getURL(String s) {     
              //Check string if it has http:// and truncate if it does
              if (s.indexOf("http://") >  -1) {
                   s = s.substring(s.indexOf("http://") + 7, s.length());
              //check if not mailto: do not print otherwise
              if (s.indexOf("mailto:") != -1) return;
              //printout anything after http:// and the next '/'
              //if no '/' then print all
                   if (s.indexOf('/') > -1) {
                        System.out.println(s.substring(0, s.indexOf('/')));
                   } else System.out.println(s);
    }Hope this helps. I used static methods instead of encapsulating everyting into a class.

Maybe you are looking for

  • Many problems with migration OBIEE

    Hi, I upgrade muy proyect obiee 10.2 to 11.1.1.5 and some dashboard displays errors. Some dashboard error says: State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 43113] Message returned

  • Migration from weblogic6.1 to OC4J

    Hi, We are evaluating OC4J to migrate our application (EJB2.0). Currently we are evaluating weblogic6.1 too. We have 66 local entity beans and 7 session Facade(for those local Entities) beans. It's perfectly working with weblogic. Here I would like t

  • Cannot enter BIOS or boot from LSI MegaRAID SAS 9271-8i

    Hello, I have a LSI MegaRAID SAS 9271-8i installed in a C220 M3 (in PCIe1). When I go to CIMC, I can see the adapter there and I can create RAID arrays. I can set the first logical drive to be the boot drive too without a problem. If I boot from ESXi

  • Sierra and Bates error?

    I'm currently studying for SCJP5 (or 6 maybe if it turns out to be no more than a few classes different) and using the book "SCJP Sun Certified Programmer for Java 5 Study Guide (Exam 310-055)" by Kathy Sierra and Bert Bates. Generally I think this b

  • Pro Res/ HQ

    Hi there, Quick question folks, I'm importing footage from some AVCHD mini-cameras via log & transfer. I'm trying to import the footage as Pro Res HQ, and have set my capture preset accordingly. However, the first clip imports and it seems like it is