Search in sources :

Example 61 with BufferedInputStream

use of java.io.BufferedInputStream in project j2objc by google.

the class OldBufferedInputStreamTest method test_available.

public void test_available() {
    // Test for method int java.io.BufferedInputStream.available()
    try {
        assertTrue("Returned incorrect number of available bytes", is.available() == fileString.length());
    } catch (IOException e) {
        fail("Exception during available test");
    }
    // Test that a closed stream throws an IOE for available()
    BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(new byte[] { 'h', 'e', 'l', 'l', 'o', ' ', 't', 'i', 'm' }));
    int available = 0;
    try {
        available = bis.available();
        bis.close();
    } catch (IOException ex) {
        fail();
    }
    assertTrue(available != 0);
    try {
        bis.available();
        fail("Expected test to throw IOE.");
    } catch (IOException ex) {
    // expected
    } catch (Throwable ex) {
        fail("Expected test to throw IOE not " + ex.getClass().getName());
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException)

Example 62 with BufferedInputStream

use of java.io.BufferedInputStream in project spring-loaded by spring-projects.

the class SerializeG method loadBytesFromStream.

public static byte[] loadBytesFromStream(InputStream stream) {
    try {
        BufferedInputStream bis = new BufferedInputStream(stream);
        byte[] theData = new byte[10000000];
        int dataReadSoFar = 0;
        byte[] buffer = new byte[1024];
        int read = 0;
        while ((read = bis.read(buffer)) != -1) {
            System.arraycopy(buffer, 0, theData, dataReadSoFar, read);
            dataReadSoFar += read;
        }
        bis.close();
        // Resize to actual data read
        byte[] returnData = new byte[dataReadSoFar];
        System.arraycopy(theData, 0, returnData, 0, dataReadSoFar);
        return returnData;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) IOException(java.io.IOException)

Example 63 with BufferedInputStream

use of java.io.BufferedInputStream in project Cloud9 by lintool.

the class HadoopAlign method loadVocab.

public static Vocab loadVocab(Path path, Configuration job) throws IOException {
    org.apache.hadoop.conf.Configuration conf = new org.apache.hadoop.conf.Configuration(job);
    FileSystem fileSys = FileSystem.get(conf);
    DataInput in = new DataInputStream(new BufferedInputStream(fileSys.open(path)));
    VocabularyWritable at = new VocabularyWritable();
    at.readFields(in);
    return at;
}
Also used : DataInput(java.io.DataInput) Configuration(org.apache.hadoop.conf.Configuration) BufferedInputStream(java.io.BufferedInputStream) Configuration(org.apache.hadoop.conf.Configuration) FileSystem(org.apache.hadoop.fs.FileSystem) VocabularyWritable(edu.umd.hooka.VocabularyWritable) DataInputStream(java.io.DataInputStream)

Example 64 with BufferedInputStream

use of java.io.BufferedInputStream in project Cloud9 by lintool.

the class HadoopAlign method loadVocab.

public static Vocab loadVocab(Path path, FileSystem fileSys) throws IOException {
    DataInput in = new DataInputStream(new BufferedInputStream(fileSys.open(path)));
    VocabularyWritable at = new VocabularyWritable();
    at.readFields(in);
    return at;
}
Also used : DataInput(java.io.DataInput) BufferedInputStream(java.io.BufferedInputStream) VocabularyWritable(edu.umd.hooka.VocabularyWritable) DataInputStream(java.io.DataInputStream)

Example 65 with BufferedInputStream

use of java.io.BufferedInputStream in project Cloud9 by lintool.

the class CLI_Int2Words method main.

/**
	 * @param args
	 */
public static void main(String[] args) {
    // TODO Auto-generated method stub
    if (args.length != 1) {
        System.err.println("Usage: CLI_Int2Words <vocfile.dat>");
        System.exit(1);
    }
    try {
        Path pve = new Path(args[0]);
        org.apache.hadoop.conf.Configuration conf = new org.apache.hadoop.conf.Configuration();
        FileSystem fileSys = FileSystem.get(conf);
        DataInputStream dis = new DataInputStream(new BufferedInputStream(fileSys.open(pve)));
        VocabularyWritable v = new VocabularyWritable();
        v.readFields(dis);
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        String l = null;
        while ((l = r.readLine()) != null) {
            String[] nums = l.split("\\s+");
            //System.err.println("words: " + nums.length);
            for (String n : nums) {
                if (n.length() == 0)
                    continue;
                System.out.print(v.get(Integer.parseInt(n)));
                System.out.print(' ');
            }
            System.out.println();
        }
    } catch (IOException e) {
        System.err.println("Caught: " + e);
        System.exit(1);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) BufferedInputStream(java.io.BufferedInputStream) FileSystem(org.apache.hadoop.fs.FileSystem) BufferedReader(java.io.BufferedReader)

Aggregations

BufferedInputStream (java.io.BufferedInputStream)1700 FileInputStream (java.io.FileInputStream)854 IOException (java.io.IOException)836 InputStream (java.io.InputStream)707 File (java.io.File)449 BufferedOutputStream (java.io.BufferedOutputStream)228 FileOutputStream (java.io.FileOutputStream)218 DataInputStream (java.io.DataInputStream)168 ByteArrayInputStream (java.io.ByteArrayInputStream)159 FileNotFoundException (java.io.FileNotFoundException)147 URL (java.net.URL)147 ZipEntry (java.util.zip.ZipEntry)123 ByteArrayOutputStream (java.io.ByteArrayOutputStream)112 OutputStream (java.io.OutputStream)100 ZipInputStream (java.util.zip.ZipInputStream)72 GZIPInputStream (java.util.zip.GZIPInputStream)68 ArrayList (java.util.ArrayList)62 HashMap (java.util.HashMap)62 HttpURLConnection (java.net.HttpURLConnection)61 ObjectInputStream (java.io.ObjectInputStream)56