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.

Similar Messages

  • 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.

  • 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

  • Java.io.Reader to String conversion

    I am working on a SOAP project with Jaxm and I retreive the result as a Reader, but I need to convert it into a String.
    I did the following code but it is incredibely slow with a big reply (280kb) as I retrieve each character one after each other.
    Does a faster solution exist ?
    // Soap call
    SOAPMessage reply = m_conn.call(message, endpoint);
    java.util.Iterator it = reply.getAttachments();
    // First attachment returned by the server hold my result
    AttachmentPart resultAttachment = (AttachmentPart) it.next();
    StreamSource resultStreamSource = (StreamSource) resultAttachment.getContent();
    // Converts java.io.Reader to String
    java.io.Reader resultReader = resultStreamSource.getReader();
    String result = "";
    int charValue = 0;
    while ((charValue = resultReader.read()) != -1) {
       result = result + (char) charValue;

    use a BufferedReader and create a large char[] (64k or something)
    then use
    char[] cbuf = new char[65536];
    StringBuffer stringbuf = new StringBuffer();
    int read_this_time = 0;
    while (read_this_time != -1) {
    read_this_time = BufferedReader.read(cbuf,0,65536);
    stringbuf.append(cbuf,0,read_this_time);
    }//end while
    StringBuffer is faster than String concatenation because when java concatenates strings it creates a new object every time. StringBuffer just stores and appends the string without creating new objects.

  • Java.io.Reader - java.io.InputStream

    Hi!
    Is there a way to wrap a java.io.Reader into an java.io.InputStream (like java.io.InputStreamReader does but in the other direction)?
    I found now class doing this job (deduced from java.io.InputStream, taking an java.io.Reader as Constructor Parameter) :-/
    If I want to write my own wrapper I've got two problems:
    * If I want to read data I have to split the char which I read from the wrapped java.io.Reader into a high and a low byte and than return two values.
    * But if I want to read text I can't just split the char into two bytes but I have to convert it
    How can I solve this problem?

    Is there a way to wrap a java.io.Reader into an java.io.InputStream (like java.io.InputStreamReader does but in the other direction)?Why don't you explain what the real problem is? I suspect that there's a solution, but you need to state it. What was the creator and source of the information (file?) that you're trying to read that contains "data" and, apparently, Java characters in a different charset?

  • Java.io.Reader byte2char conversion???

    Hi!
    What encoding java.io.Reader uses to convert read bytes to chars?
    What to do if I need to read several text files written in different encodins?
    It seems that readers use default OS encoding to read text files and changing of default Locale doesn't take any effect. Is there any method to change the default encoding for readers?
    Anton

    What encoding java.io.Reader uses to convert read
    bytes to chars?It depends on the Reader. The usual choice is some default based on your system.
    What to do if I need to read several text files
    written in different encodins?
    It seems that readers use default OS encoding to read
    text files and changing of default Locale doesn't take
    any effect. Is there any method to change the default
    encoding for readers?You use an InputStreamReader, which allows you to specify the encoding. RTFM for more details.

  • 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.
    }

  • Problem while using read(char[]) method of stream

    Hi I am trying to read different xml files, , hence i am using a buffered reader, and the read(char[]) method in the bufferereader.
    //rawContent - is the xml file content
          BufferedReader br = new BufferedReader(new InputStreamReader(rawContent,
              ENCODING_FORMAT));
          int ascii = 0;
          char ch[]= new char[200];
          while((ascii = br.read(ch)) != -1) {       
            rawContentBuffer.append(ch);
          }This is the error that i get when i execute the above piece of code. I have checked the files they have no white spaces after the xml contents.
    Please tell me how i can overcome this.
    2006-02-17 19:43:52,826 ERROR [com.test.web.taglib.LightTag] - Error in parsing the XHTMLContent is not allowed in trailing section.
    org.xml.sax.SAXParseException: Content is not allowed in trailing section.
          at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
          at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
          at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
          at com.test.web.taglib.LightTag.renderField(LightTag.java:293)
          at com.test.web.taglib.LightTag.doStartTag(LightTag.java:128)

    Maybe it isn't. I don't know what 'rawContentBuffer' is, but you're assuming that 'ch' is always full when you call rawContentBuffer.append(ch). You need to call rawContentBuffer.append(ch,0,ascii) or some such form if there is one, or make some other arrangement for handling short reads.

  • How to read BLOBs as "Java.io.Reader"

    Hello,
    I have a problem dealing with BLOBs in JDBC. I want to get a BLOB as a "java.io.Reader". I have written the following code:
    class Db_templates {
    public static Reader select(int tpl_id) {
    try {
    Connection connection = ... ;
    Reader retour = null;
    String strSQL = "SELECT tpl_blob FROM templates WHERE tpl_id = ?";
    PreparedStatement ps = connection.prepareStatement(strSQL);
    ps.setInt(1, tpl_id);
    ResultSet rset = ps.executeQuery();
    if (rset.next()) {
    oracle.sql.BLOB blob = (BLOB)rset.getObject(1);
    retour = blob.characterStreamValue();
    rset.close();
    ps.close();
    connection.close();
    return retour;
    } catch (SQLException e) {
    return null;
    Then I try to call this method in a JSP file (Tomcat 4.0 as JSP container) with the following lines:
    Reader i = Db_templates.select(42);
    out.println(i.ready());
    char buf[] = new char[1000];
    try {
    int retour = i.read(buf, 1, 900);
    } catch (IOException e) {
    out.println(e.toString());
    The method i.ready() returns false with no IOException thrown.
    The method i.read() fails to execute with the following errors:
    java.lang.NullPointerException
    at oracle.sql.LobPlsqlUtil.plsql_read(LobPlsqlUtil.java:911)
    at oracle.sql.LobPlsqlUtil.plsql_read(LobPlsqlUtil.java:52)
    at oracle.jdbc.dbaccess.DBAccess.lobRead(DBAccess.java:658)
    at oracle.sql.LobDBAccessImpl.getBytes(LobDBAccessImpl.java:95)
    at oracle.sql.BLOB.getBytes(BLOB.java:175)
    at oracle.jdbc.driver.OracleBlobInputStream.needBytes(OracleBlobInputStream.java:126)
    at oracle.jdbc.driver.OracleBufferedStream.read(OracleBufferedStream.java:108)
    at oracle.jdbc.driver.OracleConversionReader.needChars(OracleConversionReader.java:151)
    at oracle.jdbc.driver.OracleConversionReader.read(OracleConversionReader.java:119)
    at org.apache.jsp.essai2$jsp._jspService(essai2$jsp.java:87)
    Any ideas?
    Thanks,
    Nicolas

    Normally, Firefox has two different behaviors for the down arrow key, assuming it is not inside a form control:
    * Scroll the page
    * With caret browsing turned on, move the cursor down one line
    If you are accustomed to the down arrow key moving among search results so you can press the Enter key to load them, and you are using Google, this is due to a script in the results page intercepting those keys and changing what they normally do.
    I have only tested Windows myself, so I don't know whether this is generally available when using Google in your distribution of Linux. If it is, then the question would be: why not on your Firefox? Hmm...

  • Reading char from keyboard to stop threads?

    I want to kill all the threads an terminate my program execution when I enter some char, for example 'S'.
    BUT, I dont want the execution flow to wait in the sentence 'prompt.read()' until I enter some character.
    does somebody knows the solution?
    this is my program:
    import java.io.*;
    public class Finalizadora extends Thread {
         public static boolean ejecucion = true;
         public void run() {
              while (ejecucion) {
                   try {
                        sleep(1000);
                   } catch (Exception e) {
                        // Si falla el sleep lo simulamos
                        for (int i = 0; i < 1000 * 10; i++) {
                        } // fin del for
                   } // fin del try
                   try {
                        BufferedReader prompt = new BufferedReader(new InputStreamReader (System.in));
                        if (prompt.read() == 'S') {
                            ejecucion = false;
                        } // fin del if
                   } catch (Exception e) {
                        System.out.println("SOME FAILS!!");
                   //System.out.println("--------------------");
              } // fin del while
              System.out.println("ENDING...");          
         } // fin de parsear
    } // fin de Finalizadorathanks!

    Hello.I cant read chars from a file.I am trying to fing to character with Max Occurrence in a file but when I run it it stops abruptly.This is my code.Can you help me please.Thank you
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    * @author Dimitrios
    /*Assuming that the char with the max frequency in an standard English test is 'E' we can guess
    * that the char with the max frequency in the cipher text is E.This will
    * lead us to an approximation of the Key by shifting */
    import java.io.*;
    public class Frequency_Decprypt {
    public static int Occurrence(String str, char ch) {
    int occur=0;//the occurrence of char ch in the string
    for(int i=0;i<str.length();i++){
    if(str.charAt(i)==ch){
    occur++;
    return occur;
    public static char Frequency() throws IOException{
    BufferedReader in;
    FileReader fr;
    int key=0;
    char Max_FreqChar=' ';//the char with the max frequency
    int Max_Freq=0;// the max frequency of a char
    try{
    fr=new FileReader("Encrypted.txt");//the input file to read
    in=new BufferedReader(fr);
    //read a line from file
    String s=in.readLine();
    while(s!=null){
    for(int i=0;i<s.length();i++){
    if(Occurrence(s,s.charAt(i))>=Max_Freq){
    Max_Freq=Occurrence(s,s.charAt(i));
    Max_FreqChar=s.charAt(i);
    s=in.readLine();
    fr.close();
    //key=(int)('e'-Max_FreqChar);
    //key=Math.abs(key);
    } catch (FileNotFoundException e)
    { System.out.println("File not found");}
    return Max_FreqChar;
    }

  • Cost of Java Card, Reader, Tools etc

    Hello All..
    I could see old data about cost of Java Card, Reader, tools etc discussed way back in feb 2006..
    Does any one have recent cost data who can share here.
    Like to know approximate cost that i should incur to buy Java Card, Reader, associated tools,IDE etc.
    it would be nice to discuss about vendor details and cost of the product they offer.
    thanks

    The major factor in determining cost is quantity. The more u want, the cheaper they cost. For developer cards, manufacturers already have them "on the shelf" so there's no manufacturing cost involved. But as you move to real-world deployment, then you start getting a different cost model. Then issues of applets, card management systems, infrastructure start to affect the cost of a card. I've had a business model that made the total price of one 32k java card cost $100 due to those factors.
    As far as readers go, it's different. Assuming you want desktop readers, you need to deal with issues of lost readers, PCMCIA or USB. Most deployments I've dealt with went with USB so they are portable to multiple hardware.
    Assuming you mean development tools, JCOP is the king so far. For deployment tools, well that's expensive mainly because the players use a closed proprietary solution. Also, if you are doing PKI deployments, then you'll need a CA and then HSMs come into play and that just recks havoc on costing !!!!!
    Happy Deployment !!!!!

  • How to NOT ignore java beans read only properties when serializing Java to AS?

    As stated in the Adobe LCDS documentation, the read-only properties of a java bean are ignored in the AMF serialization process.
    Would you know what to do so that Java beans read only properties do not get discarded when sending it via BlazeDS AMF?
    Many thanks in advance.

    Hi,
    I've managed to get what I needed by using a shift register + event structure as suggested by Adnan. However, I face another problem after implementing SR+event. I've attached two files, first the original program and second the updated program using SR + event. (it's only the jpg file as I've forgotten to save the labview program, will upload the program by tomorrow.
    In the original program, I have an elapsed time that is able to run continuously when I run the program. In the updated program, my elapsed time don't seem to run continuously when I run the program (as shown by elapsed time indicator). I need the elapsed time to run continuously as a input to calculate my motor profile.
    I suppose this is caused by the introduction of the event structure, will adding a case structure to wrap the event structure solve the problem or is there another way to get pass this. Appreciate if someone could drop me a pointer or two.
    Thanks
    Attachments:
    Mar 16 - continuous elapsed time.png ‏12 KB
    Mar 16 - elapsed time not continuous after introducing shift register + event structure.png ‏17 KB

  • Hi there, I need to be able to read raw files from an Olympus Stylus 1 via CS5 and Lightroom 4.  I have downloaded Raw file plug-in v 6.7.1 but still can't read the files.

    Hi there, I need to be able to read raw files from an Olympus Stylus 1 via CS5 and Lightroom 4.  I have downloaded Raw file plug-in v 6.7.1 but still can't read the files?

    Read this table http://helpx.adobe.com/creative-suite/kb/camera-raw-plug-supported-cameras.html
    The Olympus Stylus 1 was first supported in Camera Raw 8.3 which is only compatible with CS6 and CC.
    It is not compatible with CS5 or older and never will be.
    If you do not want to upgrade to CS6 or CC then you can dwonload the free Adobe DNG converter, convert all Stylus 1 Raw files to DNGs then edit the DNGs in CS5.
    Camera raw, DNG | Adobe Photoshop CC

  • Need a function module to read some std. fields in service process in CIC

    Hi All,
        Process is -
    > user creating service process doc. in/from CIC (win client). SAP CRM 3.1 Version.
    Under service document's interaction record there are few fields (category, priority, reason, status, result). Using FM: crm_order_read, am able to read/find category, priority & status. But am not able to read/find reason & result. Can you please help me for this which function module i need to use. Or is there any other method is there to find out.
    Sunil

    Hi Sunil,
    You would find the reason data in ET_SERVICE_OS output parameter of CRM_ORDER_READ.
    Go to ET_SERVICE_OS ->OSSET ->SUBJECT-> CODEGRUPPE, CODE, KURZTEXT, CODETEXT.
    Hope this helps!
    Regards,
    Saumya

Maybe you are looking for