Logo Search packages:      
Sourcecode: jflex version File versions

static void StraightStreamReader::main ( String[]  args  )  [inline, static, private]

Regression test for this class. If this class is working, this should run and print no errors.

This method creates a tempory file in the working directory called "test.txt". This file should not exist before hand, and the program should have create, read, write, and delete access to this file.

Parameters:
args command line arguments (ignored)

Definition at line 193 of file StraightStreamReader.java.

References close(), in, read(), and StraightStreamReader().

                                           {
        try {
            File f = new File("test.txt");
            if (f.exists()){
                throw new IOException(f + " already exists.  I don't want to overwrite it.");
            }
            StraightStreamReader in;
            char[] cbuf = new char[0x1000];
            int read;
            int totRead;

            // write a file with all possible values of bytes
                  FileOutputStream out = new FileOutputStream(f);
            for (int i=0x00; i<0x100; i++){
                out.write(i);
            }
            out.close();

            // read it back using the read single character method
            in = new StraightStreamReader(new FileInputStream(f));
            for (int i=0x00; i<0x100; i++){
                read = in.read();
                if (read != i){
                  System.err.println("Error: " + i + " read as " + read);
                }
            }
            in.close();

            // read as much of it back as possible with one simple buffer read.
            in = new StraightStreamReader(new FileInputStream(f));
            totRead = in.read(cbuf);
            if (totRead != 0x100){
                System.err.println("Simple buffered read did not read the full amount: 0x" + Integer.toHexString(totRead));
            }
            for (int i=0x00; i<totRead; i++){
               if (cbuf[i] != i){
                  System.err.println("Error: 0x" + i + " read as 0x" + cbuf[i]);
                }
            }
            in.close();

            // read it back using buffer read method.
            in = new StraightStreamReader(new FileInputStream(f));
            totRead = 0;
            while (totRead <= 0x100 && (read = in.read(cbuf, totRead, 0x100 - totRead)) > 0){
                totRead += read;
                  }
            if (totRead != 0x100){
                System.err.println("Not enough read. Bytes read: " + Integer.toHexString(totRead));
            }
            for (int i=0x00; i<totRead; i++){
               if (cbuf[i] != i){
                  System.err.println("Error: 0x" + i + " read as 0x" + cbuf[i]);
                }
            }
            in.close();

            // read it back using an offset buffer read method.
            in = new StraightStreamReader(new FileInputStream(f));
            totRead = 0;
            while (totRead <= 0x100 && (read = in.read(cbuf, totRead+0x123, 0x100 - totRead)) > 0){
                totRead += read;
                  }
            if (totRead != 0x100){
                System.err.println("Not enough read. Bytes read: " + Integer.toHexString(totRead));
            }
            for (int i=0x00; i<totRead; i++){
               if (cbuf[i+0x123] != i){
                  System.err.println("Error: 0x" + i + " read as 0x" + cbuf[i+0x123]);
                }
            }
            in.close();

            // read it back using a partial offset buffer read method.
            in = new StraightStreamReader(new FileInputStream(f));
            totRead = 0;
            while (totRead <= 0x100 && (read = in.read(cbuf, totRead+0x123, 7)) > 0){
                totRead += read;
                  }
            if (totRead != 0x100){
                System.err.println("Not enough read. Bytes read: " + Integer.toHexString(totRead));
            }
            for (int i=0x00; i<totRead; i++){
               if (cbuf[i+0x123] != i){
                  System.err.println("Error: 0x" + i + " read as 0x" + cbuf[i+0x123]);
                }
            }
            in.close();

            f.delete();
        } catch (IOException x){
            System.err.println(x.getMessage());
            }
      }


Generated by  Doxygen 1.6.0   Back to index