Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4072657

FileOutputStream : write lost 1 byte per about 8K bytes.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.1.3
    • core-libs
    • None
    • x86
    • windows_95



      Name: rlT66838 Date: 08/18/97


      I use FileOutputStream to read a file written in
       KSC5601 code( YES, I use Korean Windows 95. )
      When I write more than 8K bytes, I lost 8193th byte.
      No error message. I tested at JDK 1.1.1 and 1.1.3.

      Here is the source code.

      [ start of File IOLine.java ]

      import java.io.*;
      import java.util.*;

      public class IOLine{
      FileOutputStream fos;
      FileInputStream fis;
      OutputStreamWriter osw;
      InputStreamReader isw;

      StringBuffer strBuf = new StringBuffer();
      char ch;
      File file;
      int last = 0;
      int tempint = 0;

      public final static int READ = 1;
      public final static int WRITE = 2;
      private int MODE = 0;

      public IOLine(String fileName, String mode) throws IOException{
      if(mode.equalsIgnoreCase("rw")){
      fos = new FileOutputStream( fileName );
      osw = new OutputStreamWriter( fos );
      MODE = WRITE;
      }else{
      fis = new FileInputStream( fileName );
      isw = new InputStreamReader( fis );
      MODE = READ;
      }
      }

      public String readLine() throws IOException{
      strBuf.setLength(0);
      try{
      while(true){
      tempint = isw.read();
      ch = (char)tempint;
      if(tempint == -1){
      if(last == -1)
      return null;
      else {
      last = -1;
      return (strBuf.toString() + " ");
      }
      }
      if(ch == '\n'){
      return strBuf.toString();
      }
      if(ch != '\r')
      strBuf.append(ch);
      }
      }catch(IOException e){
      throw new IOException();
      }
      }

      public void close() throws IOException{
      if(MODE == WRITE){
      osw.close();
      fos.close();
      }else{
      isw.close();
      fis.close();
      }
      }

      int bugCount = 0;
      byte[] bugBuffer;

      public void writeLine(String str) throws IOException{

      osw.write(str+"\r\n", 0,str.length()+2);
      }

      public void write(String str) throws IOException{

      osw.write(str, 0,str.length());
      }

      }

      [ end of File IOLine.java ]

      [ start of File IOLineTest.java ]

      import java.io.*;

      public class IOLineTest{

      public static void main( String argv[] ){
      try{
      IOLine io = new IOLine( "text.txt", "rw" );
      for( int i=0; i < 2000; i++ ){
      io.write( "123456789\n" );
      }
      io.close();
      }catch( IOException ioe ){}
      }


      }

      [ end of File IOLineTest.java ]

      How to see the bug...
          1. Excute "IOLineTest.class".
             It will make "text.txt" file
             which has 10 bytes per line.

          2. Load "text.txt" with any text file viewer.
             Find a line which is differ from other lines.
             ( maybe 820th line. )
             It maybe look like this.
                   "12456789" <-- No "3".

      Please Fix this BUG. If possible, give me a patch
      for this or the way avoid this bug.


      company - JAZZNET Korea , email - ###@###.###
      ======================================================================

            ssenthilsunw Shanmugam Senthil (Inactive)
            rlewis Roger Lewis (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: