public Connection(InputStream in, OutputStream out) { this.in = in; this.out = out; this.din = new DataInputStream(in); this.dout = new DataOutputStream(out); }
public PackedInputArray( byte[] bytes ) { this.bytes = new ByteArrayInputStream( bytes ); this.data = new DataInputStream( this.bytes ); }
import java.io.DataInputStream; DataInputStream dis = new DataInputStream(System.in); int i = dis.readInt();
private boolean checkMagic(File file, long magic) throws IOException { DataInputStream in = new DataInputStream(new FileInputStream(file)); try { int m = in.readInt(); return magic == m; } finally { in.close(); } }
/** * Main method. * * @param args <code>args[0]</code> is the class file name. */ public static void main(String[] args) throws Exception { if (args.length != 1) { System.err.println("Usage: java Dump <class file name>"); return; } DataInputStream in = new DataInputStream( new FileInputStream(args[0])); ClassFile w = new ClassFile(in); PrintWriter out = new PrintWriter(System.out, true); out.println("*** constant pool ***"); w.getConstPool().print(out); out.println(); out.println("*** members ***"); ClassFilePrinter.print(w, out); } }
public void read(String binaryFile) throws IOException { DataInputStream dis = new DataInputStream(new FileInputStream(new File(binaryFile))); read(dis); }
public static void main(String... args) throws IOException { final String filename = args[0]; final File file = new File(filename); DataInputStream dis = new DataInputStream(new FileInputStream(file)); byte[] bytes = new byte[(int) file.length()]; dis.readFully(bytes); System.out.println("Average latency " + latency + " ns. Bandwidth " + bandwidth + " MB/s.");
public Connection(Socket sock) throws IOException { this.sock=sock; this.in=new DataInputStream(sock.getInputStream()); this.out=new DataOutputStream(sock.getOutputStream()); }
writeFile("numbers2.bin", nums); long time = System.currentTimeMillis() - start; System.out.println("Took "+time+" secs to sort "+nums.length+" numbers."); DataInputStream dis = new DataInputStream(new BufferedInputStream(new FileInputStream(filename), 64*1024)); int len = dis.readInt(); int[] ints = new int[len]; for(int i=0;i<len;i++) ints[i] = dis.readInt(); return ints; DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(name), 64*1024)); dos.writeInt(numbers.length); for (int number : numbers)
byte[] test = new byte[] {0, 0, 1, 0, 0, 0, 1, 1, 8, 9}; DataInputStream stream = new DataInputStream(new ByteArrayInputStream(test)); int value0 = stream.readInt(); int value1 = stream.readInt(); byte value2 = stream.readByte(); byte value3 = stream.readByte(); stream.close(); System.out.println(value0 + " " + value1 + " " + value2 + " " + value3);
import java.io.*; public class ClassVersionChecker { public static void main(String[] args) throws IOException { for (int i = 0; i < args.length; i++) checkClassVersion(args[i]); } private static void checkClassVersion(String filename) throws IOException { DataInputStream in = new DataInputStream (new FileInputStream(filename)); int magic = in.readInt(); if(magic != 0xcafebabe) { System.out.println(filename + " is not a valid class!");; } int minor = in.readUnsignedShort(); int major = in.readUnsignedShort(); System.out.println(filename + ": " + major + " . " + minor); in.close(); } }
void rewind() { readOffset = 0; if (useBackingFile) { try { if (readStream != null) { readStream.close(); } readStream = new DataInputStream(new BufferedInputStream(new FileInputStream(backingFile), buffer.length * 8)); readStreamClosed = false; } catch (IOException ex) { ex.printStackTrace(); } } }
public void seek(long seekBytes) throws FileNotFoundException, IOException, InterruptedException { fileInput = new FileInputStream(file); fileChannel = fileInput.getChannel(); try { fileChannel.position(seekBytes); } catch (ClosedByInterruptException e) { throw new InterruptedException(); } bufferedInput = new BufferedInputStream(fileInput, size); dataInput = new DataInputStream(bufferedInput); offset = seekBytes; }
private static void doTestSerializationRoundTrip(DownloadAction action) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); DataOutputStream output = new DataOutputStream(out); DownloadAction.serializeToStream(action, output); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); DataInputStream input = new DataInputStream(in); DownloadAction action2 = DownloadAction.deserializeFromStream( new DownloadAction.Deserializer[] {ProgressiveDownloadAction.DESERIALIZER}, input); assertThat(action2).isEqualTo(action); }
music=new byte[(int) file.length()];//size & length of the file InputStream is = new FileInputStream (file); BufferedInputStream bis = new BufferedInputStream (is, 8000); DataInputStream dis = new DataInputStream (bis); // Create a DataInputStream to read the audio data from the saved file int i = 0; // Read the file into the "music" array while (dis.available() > 0) { music[i] = dis.readByte(); // This assignment does not reverse the order i++; } dis.close(); // Close the input stream
private void loadCreationMeta(File crcFile) throws IOException { if (crcFile.exists()) { final DataInputStream ds = new DataInputStream(new FileInputStream(crcFile)); _crc = ds.readLong(); _creationTime = ds.readLong(); ds.close(); } }
... byte[] imgDataBa = new byte[(int)imgFile.length()]; DataInputStream dataIs = new DataInputStream(new FileInputStream(imgFile)); dataIs.readFully(imgDataBa); ...
@Override public void revalidateSession(QuorumPacket qp, LearnerHandler learnerHandler) throws IOException { ByteArrayInputStream bis = new ByteArrayInputStream(qp.getData()); DataInputStream dis = new DataInputStream(bis); long id = dis.readLong(); int to = dis.readInt(); synchronized (revalidateSessionLock) { pendingRevalidations.add(new Revalidation(id, to, learnerHandler)); Learner learner = zks.getLearner(); if (learner != null) { learner.writePacket(qp, true); } } }
/** * Deserialization of Hadoop Writable object. * * @param writable Writable object to deserialize to. * @param bytes byte array to deserialize. */ public static void deserialize(Writable writable, byte[] bytes) throws IOException { DataInputStream dataIn = new DataInputStream(new ByteArrayInputStream(bytes)); writable.readFields(dataIn); dataIn.close(); }
@Test public void testSerialize() throws IOException { AppendTrieDictionaryBuilder builder = createBuilder(); AppendTrieDictionary dict = builder.build(0); ByteArrayOutputStream bout = new ByteArrayOutputStream(); DataOutputStream dataout = new DataOutputStream(bout); dict.write(dataout); dataout.close(); ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); DataInputStream datain = new DataInputStream(bin); assertNull(new Path(datain.readUTF()).toUri().getScheme()); datain.close(); }