Example usage for java.io EOFException getMessage

List of usage examples for java.io EOFException getMessage

Introduction

In this page you can find the example usage for java.io EOFException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:gov.nih.nci.caintegrator.application.lists.UserListGenerator.java

public static List<String> generateList(File file) {
    List<String> tempList = new ArrayList<String>();
    if (file != null && (file.getName().endsWith(".txt") || file.getName().endsWith(".TXT"))) {
        try {//from  ww w.  jav a2 s  .  c  om
            BufferedReader in = new BufferedReader(new FileReader(file));
            String inputLine = null;
            do {
                inputLine = in.readLine();

                if (inputLine != null) {
                    if (isAscii(inputLine)) { // make sure all data is ASCII                                                        
                        tempList.add(inputLine);
                    }
                } else {
                    System.out.println("null line");
                    while (tempList.contains("")) {
                        tempList.remove("");
                    }
                    in.close();
                    break;
                }

            } while (true);
        } catch (EOFException eof) {
            logger.error("Errors when reading empty lines in file:" + eof.getMessage());
        } catch (IOException ex) {
            logger.error("Errors when uploading file:" + ex.getMessage());
        }

    }

    return tempList;

}

From source file:gov.nih.nci.caintegrator.application.lists.UserListGenerator.java

public static List<String> generateList(FileItem formFile) throws IOException {

    List<String> tempList = new ArrayList<String>();

    if ((formFile != null) && (formFile.getName().endsWith(".txt") || formFile.getName().endsWith(".TXT"))) {

        try {/*from   ww  w.  j ava  2 s.c  o m*/
            InputStream stream = formFile.getInputStream();
            String inputLine = null;
            BufferedReader inFile = new BufferedReader(new InputStreamReader(stream));

            do {
                inputLine = inFile.readLine();

                if (inputLine != null) {
                    if (isAscii(inputLine)) { // make sure all data is ASCII                                                        
                        tempList.add(inputLine);
                    }
                } else {
                    System.out.println("null line");
                    while (tempList.contains("")) {
                        tempList.remove("");
                    }
                    inFile.close();
                    break;
                }

            } while (true);
        } catch (EOFException eof) {
            logger.error("Errors when reading empty lines in file:" + eof.getMessage());
        } catch (IOException ex) {
            logger.error("Errors when uploading file:" + ex.getMessage());
        }

    }

    return tempList;

}

From source file:org.pepstock.jem.ant.tasks.utilities.SortTask.java

/**
 * This will simply load the file by blocks of x rows, then sort them
 * in-memory, and write the result to temporary files that have to be merged
 * later. You can specify a bound on the number of temporary files that will
 * be created.//from  w  w w .j  av  a 2 s. co  m
 * 
 * @param fileInput some flat file
 * @param cmp string comparator
 * @param maxtmpfiles maximal number of temporary files
 * @param cs 
 * @param Charset character set to use (can use Charset.defaultCharset())
 * @param tmpdirectory location of the temporary files (set to null for
 *            default location)
 * @return a list of temporary flat files
 * @throws IOException 
 */
public static List<File> sortInBatch(FileInputStream fileInput, Comparator<String> cmp, int maxtmpfiles,
        Charset cs, File tmpdirectory) throws IOException {
    List<File> files = new ArrayList<File>();
    BufferedReader fbr = new BufferedReader(new InputStreamReader(fileInput, cs));
    // in bytes
    long blocksize = estimateBestSizeOfBlocks(fileInput, maxtmpfiles);

    try {
        List<String> tmplist = new ArrayList<String>();
        String line = "";
        try {
            while (line != null) {
                // in bytes
                long currentblocksize = 0;
                // as long as you have enough memory
                while ((currentblocksize < blocksize) && ((line = fbr.readLine()) != null)) {
                    tmplist.add(line);
                    // java uses 16 bits per character?
                    currentblocksize += line.length() * 2;
                }
                files.add(sortAndSave(tmplist, cmp, cs, tmpdirectory));
                tmplist.clear();
            }
        } catch (EOFException oef) {
            // ignore
            LogAppl.getInstance().ignore(oef.getMessage(), oef);

            if (!tmplist.isEmpty()) {
                files.add(sortAndSave(tmplist, cmp, cs, tmpdirectory));
                tmplist.clear();
            }
        }
    } finally {
        fbr.close();
    }
    return files;
}

From source file:CSVReader.java

/**
 * @param args  [0]: The name of the file.
 *//*from  w ww.  j a  v a  2 s  . co  m*/
private static void testSingleTokens(String[] args) {
    if (debugging) {
        try {
            // read test file
            CSVReader csv = new CSVReader(new FileReader(args[0]), ',');
            try {
                while (true) {
                    System.out.println(csv.get());
                }
            } catch (EOFException e) {
            }
            csv.close();
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println(e.getMessage());
        }
    } // end if
}

From source file:com.ibm.stocator.fs.swift.SwiftInputStreamWrapper.java

@Override
public int read() throws IOException {
    verifyClosed();//from   ww w.j  a  va 2 s .  com
    int read = 0;
    try {
        read = inStream.read();
    } catch (EOFException e) {
        LOG.error(e.getMessage());
        read = -1;
    } catch (IOException e) {
        LOG.error(e.getMessage());
        throw closeAndThrow(e);
    }
    if (read < 0) {
        finishReading = true;
        LOG.debug("No more left to read");
        innerClose();
    }
    return read;
}

From source file:com.ibm.stocator.fs.swift.SwiftInputStreamWrapper.java

@Override
public int read(byte[] b, int off, int len) throws IOException {
    verifyClosed();/*w  w  w .  j  a  v a 2  s .c  om*/
    int read;
    try {
        read = inStream.read(b, off, len);
    } catch (EOFException e) {
        LOG.error(e.getMessage());
        read = -1;
    } catch (IOException e) {
        LOG.error(e.getMessage());
        throw closeAndThrow(e);
    }
    if (read < 0) {
        finishReading = true;
        LOG.debug("No more data to read");
        innerClose();
    }
    return read;
}

From source file:org.apache.shindig.gadgets.http.BasicHttpFetcherTest.java

@Test
public void testToByteArraySafeThrowsException2() throws Exception {
    String exceptionMessage = "EOF Exception and Any Random Cause";
    EOFException e = new EOFException(exceptionMessage);
    EasyMock.expect(mockInputStream.read(EasyMock.isA(byte[].class))).andThrow(e).anyTimes();

    EasyMock.replay(mockEntity, mockInputStream);
    boolean exceptionCaught = false;

    try {/*from w ww  .  j a va  2  s . com*/
        fetcher.toByteArraySafe(mockEntity);
    } catch (EOFException eofe) {
        assertEquals(exceptionMessage, eofe.getMessage());
        exceptionCaught = true;
    }
    assertTrue(exceptionCaught);
    EasyMock.verify(mockEntity, mockInputStream);
}

From source file:org.apache.shindig.gadgets.http.BasicHttpFetcherTest.java

@Test
public void testToByteArraySafeThrowsException3() throws Exception {
    EasyMock.reset(mockInputStream);//w  w  w .  j  a  v a  2s .com
    mockInputStream.close();

    // Return non-zero for 'InputStream.available()'. This should violate the other condition.
    EasyMock.expect(mockInputStream.available()).andReturn(1);
    String exceptionMessage = "Unexpected end of ZLIB input stream";
    EOFException e = new EOFException(exceptionMessage);
    EasyMock.expect(mockInputStream.read(EasyMock.isA(byte[].class))).andThrow(e).anyTimes();

    EasyMock.replay(mockEntity, mockInputStream);
    boolean exceptionCaught = false;

    try {
        fetcher.toByteArraySafe(mockEntity);
    } catch (EOFException eofe) {
        assertEquals(exceptionMessage, eofe.getMessage());
        exceptionCaught = true;
    }
    EasyMock.verify(mockEntity, mockInputStream);
    assertTrue(exceptionCaught);
}

From source file:org.apache.mrql.Main.java

public int run(String args[]) throws Exception {
    Config.parse_args(args, conf);// w  w  w .  j a v a2  s .com
    Evaluator.init(conf);
    System.out.print("Apache MRQL version " + version + " (");
    if (Config.compile_functional_arguments)
        System.out.print("compiled ");
    else
        System.out.print("interpreted ");
    if (Config.hadoop_mode) {
        if (Config.local_hadoop_mode)
            System.out.print("local ");
        else
            System.out.print("distributed ");
        if (Config.bsp_mode)
            System.out.println("Hama BSP mode over " + Config.bsp_tasks + " BSP tasks)");
        else if (Config.reduce_tasks > 0)
            System.out.println("Hadoop MapReduce mode with " + Config.reduce_tasks + " reducers)");
        else if (!Config.local_hadoop_mode)
            System.out.println("Hadoop MapReduce mode with 1 reducer, use -reducers to change it)");
        else
            System.out.println("Hadoop MapReduce mode)");
    } else if (Config.bsp_mode)
        System.out.println("in-memory BSP mode)");
    else
        System.out.println("in-memory MapReduce mode)");
    if (Config.interactive) {
        System.out.println("Type quit to exit");
        ConsoleReader reader = new ConsoleReader();
        reader.setBellEnabled(false);
        History history = new History(new File(System.getProperty("user.home") + "/.mrqlhistory"));
        reader.setHistory(history);
        reader.setUseHistory(false);
        try {
            loop: while (true) {
                String line = "";
                String s = "";
                try {
                    if (Config.hadoop_mode && Config.bsp_mode)
                        Config.write(Plan.conf);
                    do {
                        s = reader.readLine("> ");
                        if (s != null && (s.equals("quit") || s.equals("exit")))
                            break loop;
                        if (s != null)
                            line += " " + s;
                    } while (s == null || s.indexOf(";") <= 0);
                    line = line.substring(1);
                    history.addToHistory(line);
                    parser = new MRQLParser(new MRQLLex(new StringReader(line)));
                    MRQLLex.reset();
                    parser.parse();
                } catch (EOFException x) {
                    break;
                } catch (Exception x) {
                    if (x.getMessage() != null)
                        System.out.println(x);
                } catch (Error x) {
                    System.out.println(x);
                }
            }
        } finally {
            if (Config.hadoop_mode)
                Plan.clean();
            if (Config.compile_functional_arguments)
                Compiler.clean();
        }
    } else
        try {
            if (Config.hadoop_mode && Config.bsp_mode)
                Config.write(Plan.conf);
            parser.parse();
        } finally {
            if (Config.hadoop_mode)
                Plan.clean();
            if (Config.compile_functional_arguments)
                Compiler.clean();
        }
    ;
    return 0;
}

From source file:org.apache.hadoop.io.TestIOUtils.java

@Test
public void testSkipFully() throws IOException {
    byte inArray[] = new byte[] { 0, 1, 2, 3, 4 };
    ByteArrayInputStream in = new ByteArrayInputStream(inArray);
    try {/*from w w w .  j ava 2 s  . c  o m*/
        in.mark(inArray.length);
        IOUtils.skipFully(in, 2);
        IOUtils.skipFully(in, 2);
        try {
            IOUtils.skipFully(in, 2);
            fail("expected to get a PrematureEOFException");
        } catch (EOFException e) {
            assertEquals("Premature EOF from inputStream " + "after skipping 1 byte(s).", e.getMessage());
        }
        in.reset();
        try {
            IOUtils.skipFully(in, 20);
            fail("expected to get a PrematureEOFException");
        } catch (EOFException e) {
            assertEquals("Premature EOF from inputStream " + "after skipping 5 byte(s).", e.getMessage());
        }
        in.reset();
        IOUtils.skipFully(in, 5);
        try {
            IOUtils.skipFully(in, 10);
            fail("expected to get a PrematureEOFException");
        } catch (EOFException e) {
            assertEquals("Premature EOF from inputStream " + "after skipping 0 byte(s).", e.getMessage());
        }
    } finally {
        in.close();
    }
}