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());
}
}
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);
}
}
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;
}
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;
}
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);
}
}
Aggregations