Buffered Reader read() method

I'm trying to read a data file using the BufferedReader.read() method. Where the file is valid data I cast to a char and build up a string which then gets written to a flat file.
Some of the bytes I need to read are pointers to a position in another file. These I want to read as integers, and I would expect to be able to use the value returned by the read() method directly.
However I have a problem when the pointer byte has a value from hex 80 to 99 (I can see these using 'hex' on a LINUX system). The values returned are not what I would expect eg. where I would expect 128, I get 8364, expecting 130 I get 8218 and 131, I get 402.
Above 159, things appear to be working as I would expect.
Can anyone explain please
Thanks,
Martin

BufferedReader should only be used to read character data. The value you get from the read method is not the value that was in the file. BufferedReader simply reads character data from an underlying Reader. Your underlying reader is probably an InputStreamReader or a FileReader. Both of those readers perform a transformation from the byte data to the characters using some character encoding. If you want the actual values, you must read them from the InputStream directly or use a DataInputStream

Similar Messages

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

  • Why do I get such low bandwidth using buffered encoder reads?

    I have a PXI system with 10 6115 A/D boards and a 6608 timing board. I can do a simultaneous buffered AI at 5 MHz across all 40 channels of the 6115's.
    However, I can only do a single buffered encoder read at about 100 kHz.
    Why such a huge difference in bandwidth?

    I think the difference in bandwidth here is really due to size of the FIFO's present on each device. The 6115 has either a 16 or 32 Mega-Sample FIFO for analog input. If one of the 6115's isn't granted usage of the bus for a "large" amount of time, it can absorb this by backlogging the data into its FIFO until it is granted the bus, at which time the DMA controller will move the data to host memory before the FIFO overflows. The same is not true of the counters on the 6608. Each counter on the 6608 has an effective FIFO size of 2 Samples. This means at high sampling rates, the 6608 cannot withstand "large" amounts of time without being granted usage of the bus. How fast you can go before the counter FIFO overflows is going to be system dependent, but 200 KHz is in line with results I have observed. If you need to go faster, you can use two counter measurement methods, but you will sacrifice accuracy for speed. For example, by dividing down your input signal by 4, you will be able to go 4 times as fast, but your accuracy will also decrease by a factor of 4. You'll have to weigh the requirements of your application to determine if this type of trade off is acceptable.

  • How to read the method and put that code in 1 internal table

    Hi,
    Actually in the normal ABAP, if we want to read the report,  then we will write read report statement.
    If we want to read method then this statement will not work.
    So, to read the method and put that code in 1 internal table , which statement we need to write?
    Regards,
    Radhika

    Hi Naimesh,
    Thanks for your reply.
    As, i am not aware of ABAP Objects i am having some issues:
    Actually that is working for some methods in some classes.
    Here 1 issue is there:
    In se24 1 method is there in 1 class.
    Even by using that FM in SE37 i am able to get the program name by giving class and method name,
    but while using that FM in the program i am not able to get that program name.
    so, i am unable to read the source code of the program?
    1 example here:
    Class name is CL_GUI_FRONTEND_SERVICES.
    in this class, methods like FILE_EXIST , FILE_GET_SIZE, etc are there.
    By giving the class name and method name i am able to get the program name also,
    but while using that FM in the program i am not able to get that program name.
    so, i am unable to read the source code of the program?
    Here is my code:
    REPORT  Z16059_SCAN_METHOD.
    DATA: BEGIN OF I_PROGRAM OCCURS 0,
          LINE(256) TYPE C,
          END OF I_PROGRAM.
    DATA METHOD TYPE PROGRAM.
    DATA: BEGIN OF I_STRUCTURE,
          CLS_NAME(30) TYPE C,
          METH_NAME(61) TYPE C,
          END OF I_STRUCTURE.
    I_STRUCTURE-CLS_NAME = 'CL_GUI_FRONTEND_SERVICES'.
    I_STRUCTURE-METH_NAME = 'CL_GUI_FRONTEND_SERVICES-FILE_EXIST'.
    CALL FUNCTION 'SEO_METHOD_GET_INCLUDE_BY_NAME'
      EXPORTING
      MTDKEY             =  I_STRUCTURE
    IMPORTING
       PROGNAME          = METHOD
    EXCEPTIONS
       INTERNALMETHOD_NOT_EXISTING      = 1
       OTHERS                             = 2
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    READ REPORT METHOD INTO I_PROGRAM.
    Please help me out in this regard.
    Thanks & Regards,
    Radhika

  • [SOLVED] Poor SSD Performance, Low Buffered Disk Reads

    Hello. Today, I ran hdparm -t and noticed unusually low performance:
    /dev/sdb:
    Timing buffered disk reads: 342 MB in 3.00 seconds = 113.85 MB/sec
    This is on a Samsung 840 EVO with an FX-8320 4.5ghz. Testing /dev/sda, my mechanical hard drive, gives me nearly identical results, which makes pretty much no sense. I ran this about a week ago, and got numbers around 520 MB.
    I am using the BFQ scheduler and the Linux-ck kernel. I tried other IO schedulers, but only gotten worsened performance.
    The only thing I can think of that I've changed recently was from the performance to ondemand CPU governor. Could that have caused this?
    Any help would be appreciated. I am using UEFI/GPT. uname -a:
    Linux msw1 3.13.11-2-ck #1 SMP PREEMPT Fri Apr 25 20:19:47 PDT 2014 x86_64 GNU/Linux
    EDIT:
    Now solved! It turns out the 840 EVO with its TLC NAND is an odd SSD, and that the alignment needs to be a multiple of 1.5.
    Last edited by msw1 (2014-05-01 21:28:31)

    supermariolinux wrote:
    I have the same SSD(840 EVO) as you do and i am getting similar results with hdparm -t, although i thought this had something to do with the fact that my SSD is only connected to SATA 2.
    Partitions are aligned and manually trimming the partition doesn't seem to change anything.
    I noticed there is  new firmware update available on Samsung's website(You can boot from a CD with the ISO without having to use Windows), unfortunately i cannot get it to work as the program just crashes.
    Using the standard 3.14.1-1 x86-64 kernel with default cfq scheduler
    EDIT: It appears i already have the latest firmware installed, still i recommend checking with
    hdparm -i /dev/sdX | grep FwRev
    and seeing if new firmware is availbe here: http://www.samsung.com/global/business/ … oads.html#
    hparm -t results:
    /dev/sdc:
    Timing buffered disk reads: 368 MB in 3.01 seconds = 122.36 MB/sec
    I do have the latest firmware. As for you, it could be SATA2. I, however, have this connected to a SATA3 controller. As I said, this used to get 500+ easily. Now, it's more like 80.
    gedgon wrote:I had exactly the same issue with my EVO when it was not aligned to EBS. It's 1536 KiB or 2048 KiB (depending of source), so it's safe to set the sector alignment value to 12288 (6144 KiB), multiple of 1536 KiB and 2048 KiB.
    I wish this solved it. However, I still get the same result:
    sudo blockdev --getalignoff /dev/sdb
    0

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

  • Question for Reader.read() !

    When I read the documentation for Reader.read(), I am not sure if I understand it right or not.
    public int read():
    Read a single character. This method will block until a character is available, an I/O error occurs, or the end of the stream is reached.
    Depends on what it saying, I think when read() is called, it will always move its cursor to the next, read next character, if it is possible.
    Am I right? Any code to prove that? I am trying to do it in my own, if I get it, I will post to here too.

    Yeah you're right.
    If you use a Reader to read from a file (FileReader), then only three events can happen :
    1) there is another character availbale, so read() reads it and moves the cursor to the next character.
    2) there are no other character in the stream, so the function returns -1.
    3) there is a problem with the file system and an IOException is throwed.
    So you can read a file without creating a new thread. In this case, read() never blocks. But there are other sorts of Readers.
    For exemple, the PipedReader reads its data from a pipe. The pipe you read from can be empty but will generate no exception or end of stream events. In this case, read() will block until data is available. In most case, you will need to create a new thread to read from a pipe without blocking all your application.
    So the answer about wether read() block or not depends in fact of the actuel Channel used, and you need to read the documentation of each of these Channels (FileReader, PipedReader, etc...).
    Hope this helps.
    Matthieu

  • Does only Adobre Reader "reads" the fields of a PDF when created with Acrobat?

    I created a PDF with several fields and exported it.
    Then I tried to open it with Firefox and the fields didn't appear.
    But it works OK with Adobe Acrobat.
    Does only Adobre Reader "reads" the fields of a PDF when created with Acrobat?

    Adobe software reads form fields. The rules for how to do form fields are a part of the PDF standard (a book available to anyone) but some companies ignore it and others do half a job. To be safe, use only Adobe Reader. And beware of browsers that ignore Adobe Reader even if you have it.

  • TTS not working (in Babylon or Foxit reader read out loud or adobe reader read out loud)

    Hello
    Text to speech in applications(such as Babylon or Foxit reader read out loud
    or adobe reader read out loud) that use it does
    not work.
    Do not get any error, but when play would have no sound.
    I think this problem
    has caused the program system mechanic pro,
    It changed the registry.
    My OS is win 8.1 64 bit
    really need this functionality, please
    help me.

    Extremely grateful
    for answer.
    I try foxit reader support,
    but they could not help me.
    I think the problem
    is related to Windows.
    I previously didn't have any problem with these softwares.
    Why all three software(adobe reader, babylon, foxit) disabled at the same time?

  • How to know theis a space or carrier return when java read read a text file

    Hi,
    Please help.
    How to know theis a space or carrier return when java read read a text file.
    for example a text like this:
    5
    <---how to let tell java they is a space here
    item1
    item1
    item1
    item1
    item1
    <---how to let tell java they is a space here
    item2
    item2
    item2
    item2
    item2

    hi!
    The reason is that. I want to use java for loop to read each part of value. for example: first part is the items name. After the space (I need to tell java when this is a space here and its need to skip) , following by the items prices in double value and space again (need to skip also) and etc.
    item name1
    item name2
    item name3
    item name4
    item name5
    <--- here is the space to skip and another loop to read following items prices
    item price1
    item price2
    item price3
    item price4
    item price5
    <--- here is another spcae again. and so on
    Thank in advance for your help.
    jet

  • What is correct way to make a PDF reader, read the page numbering? (for accesibility in indesign 5.5

    What I have to do to make the reader read pdfs page numbering is in the page layout in InDesign CS5.5?
    I read that unlinking the numbering of the page layout and then including it in panel articles with the other elements. Is it true?
    Is this the way?
    thanks

    But page numbers do defenitively not belong to the text structure, neither do running headers and footers. As far as I understand these items are disturbing when reading pages.
    I am not blind and neither peronally I don't know any. But I suppose there are other means as reading marks for them as page numbers.

  • How do I search scanned documents that Adobe Reader reads but shows 0 results from the search?

    How do I search scanned documents that Adobe Reader reads but shows 0 results from the search?

    If the scanned document was not processed for OCR, then it is just an image and cannot be searched for text.

  • Unable to read "read/write" OPC tags through datasockets

    I am having problems reading tags from an OPC server that are "read/write" access. Reading "read-only" tags works good. I am using the Datasocket Open.vi and Datasocker Read.vi and I have tried to set the mode input of the Datasocket Open to "read/write" follow by a Datasocket Read without any success. I am constantly getting the 1179 error as return.  
    I have tried to read the same tags with an OPC Client software and it works fine.
    Anyone that have successfully read a "read/write" OPC tag using Datasockets?  

    Are you watching these variables in another program as well? I have seen this error pop up before when variables were on the watch list and variable manager was open.  Make sure you have nothing else grabbing the resource at the same time.
    Rob K
    Measurements Mechanical Engineer (C-Series, USB X-Series)
    National Instruments
    CompactRIO Developers Guide
    CompactRIO Out of the Box Video

  • IOException reading reader invalid first byte 11111000

    Hi,
    I have just switched from Vista to Ubuntu 8.04, and when I try to emulate a j2me application I get an exception.
    The first time I start the application (with no ~/j2mewtk/ folder) the following exception is casted:
    Running with storage root ~/j2mewtk/2.5.2/appdb/DefaultColorPhone
    Running with locale: LC_CTYPE=nb_NO.UTF-8;LC_NUMERIC=nb_NO.UTF-8;LC_TIME=nb_NO.UTF-8;LC_COLLATE=nb_NO.UTF-8;LC_MONETARY=nb_NO.UTF-8;LC_MESSAGES=en_GB.UTF-8;LC_PAPER=nb_NO.UTF-8;LC_NAME=nb_NO.UTF-8;LC_ADDRESS=nb_NO.UTF-8;LC_TELEPHONE=nb_NO.UTF-8;LC_MEASUREMENT=nb_NO.UTF-
    8;LC_IDENTIFICATION=nb_NO.UTF-8
    Running in the manufacturer security domain
    Uncaught exception java/lang/RuntimeException: IOException reading reader invalid first byte 11111000.
    Execution completed.
    22885068 bytecodes executed
    3358 thread switches
    1791 classes in the system (including system classes)
    37695 dynamic objects allocated (2415020 bytes)
    144 garbage collections (2133624 bytes collected)If I try to run the application again (with a ~/j2mewtk/ folder), this exception is cast:
    Running with storage root ~/j2mewtk/2.5.2/appdb/DefaultColorPhone
    Running with locale: LC_CTYPE=nb_NO.UTF-8;LC_NUMERIC=nb_NO.UTF-8;LC_TIME=nb_NO.UTF-8;LC_COLLATE=nb_NO.UTF-8;LC_MONETARY=nb_NO.UTF-8;LC_MESSAGES=en_GB.UTF-8;LC_PAPER=nb_NO.UTF-8;LC_NAME=nb_NO.UTF-8;LC_ADDRESS=nb_NO.UTF-8;LC_TELEPHONE=nb_NO.UTF-8;LC_MEASUREMENT=nb_NO.UTF-
    8;LC_IDENTIFICATION=nb_NO.UTF-8
    Running in the manufacturer security domain
    java.lang.RuntimeException: IOException reading reader invalid byte 11100110
         at com.sun.cldc.i18n.Helper.byteToCharArray(+228)
         at com.sun.cldc.i18n.Helper.byteToCharArray(+9)
         at java.lang.String.<init>(+7)
         at java.lang.Class.runCustomCode(+0)
         at com.sun.midp.midlet.MIDletState.createMIDlet(+34)
         at com.sun.midp.midlet.Scheduler.schedule(+52)
         at com.sun.midp.main.Main.runLocalClass(+28)
         at com.sun.midp.main.Main.main(+80)
    Execution completed.
    3739336 bytecodes executed
    51 thread switches
    1774 classes in the system (including system classes)
    27329 dynamic objects allocated (1267964 bytes)
    91 garbage collections (1149916 bytes collected)I use Sun Java Wireless Toolkit 2.5.2, MyEclipse 6.0.1 and jdk1.6.0_06. The source files are originally created in XP and Vista.
    Any tips?

    I found the error. Some of the source files or configuration files were Cp1252 encoded. When setting the jvm to use Cp1252 encoding both on server and client side, everything worked just fine.

  • URGENT!! - Bug on read (readLine) method?

    Hello to all, I have need of a large aid.
    I need to know if There is the possibility that the method read() or readLine(), than I use for reading data from a socket from a PLC, has a Bug.
    This why, with the socket opened and of the data in arrival from the PLC (than does not give to errors), the method read() raises the "Connection exception reset by peer."
    The Technicians of the PLC say not to have errors but and I am surest of the correct operation of the server socket, also why it has been tested with telnet, hyperterminaly and others client without problems.
    I do not know that what to say and what to try.
    Thanks for every eventual aid.

    I don't think there is a bug with BufferedReader. But instead of using buffered reader, you can try using the socket input stream directly for reading to see if it makes any difference:
    try {
      // if the PLC is a client:
      ServerSocket serverSocket = new ServerSocket(...);
      Socket socket = serverSocket.accept();
      // or if the PLC is a server:
      Socket socket = new Socket(...);
      // and the rest of the code to test with
      InputStream in = socket.getInputStream();
      byte[] buffer = new byte[1024];
      int length;
      while ((length = in.read(buffer)) != -1) {
        System.out.println("Read "+length+" bytes");
      System.out.println("Connection closed");
    } catch (Exception e) {
      e.printStackTrace();
    }See if that little example works.
    Is the PLC i client or server? Is the PLC the first to write something to your java program or do you have to write something to it first (maybe it doesn't understand what you write to it).
    If you use reader/writer classes, there could be problems with the character encoding you use. If you don't specify any with InputStreamReader/OutputStreamWriter, then you will use the default platform encoding. I don't know which character encoding the PLC use, but if the characters are between 0 and 255, and you really want to use reader and writer classes, then use the ISO 8859-1 encoding.

Maybe you are looking for

  • IPad does not show in iTunes devices

    I wanted to install iOS 4.2 but cannot get my iPad recognized on iTunes. When I plugged the iPad into the MBP I get an OK tone as usual. It has been connected successfully in the past. I have restarted both my MacBook Pro and iTunes in different orde

  • I downloaded the trial version of Flash 5.5. I had an error.

    So after I received the error I restarted my Windows 7 PC and started the download again.  The download finished properly but when I try and launch the application I guess a message that my trial expired.  What can I do?  I saw in another forum that

  • DB Connection how to?

    Hi, I want to open one db connection and share it (pool) with all other user's. I dont want to use open.conn close conn etc.... I'm new to EP. Thanks for any reply

  • Need drivers for Windows 7

    I originally did a bootcamp partition, making the driver CD and everything, but with windows xp, not realizing at first that bootcamp wouldn't work with xp. So I put the disk away for later use once I had a copy of Windows 7, which I now do. Unfortun

  • Shipment and cross company...

    Hi all, is it possible to use cross-company function while settling a shipment cost? ex: companyA is using transportation functions. while creating shipment, it uses companyB as forwarding agent. Both companyA and companyB are in the same client. whe