List of usage examples for java.io DataInputStream readLong
public final long readLong() throws IOException
readLong
method of DataInput
. From source file:gridool.util.xfer.TransferUtils.java
public static void send(@Nonnull final FastByteArrayOutputStream data, @Nonnull final String fileName, @Nullable final String writeDirPath, @Nonnull final InetAddress dstAddr, final int dstPort, final boolean append, final boolean sync, @Nullable final TransferClientHandler handler) throws IOException { final SocketAddress dstSockAddr = new InetSocketAddress(dstAddr, dstPort); SocketChannel channel = null; Socket socket = null;/*from w w w .j a v a2s .c o m*/ final OutputStream out; try { channel = SocketChannel.open(); socket = channel.socket(); socket.connect(dstSockAddr); out = socket.getOutputStream(); } catch (IOException e) { LOG.error("failed to connect: " + dstSockAddr, e); IOUtils.closeQuietly(channel); NetUtils.closeQuietly(socket); throw e; } DataInputStream din = null; if (sync) { InputStream in = socket.getInputStream(); din = new DataInputStream(in); } final DataOutputStream dos = new DataOutputStream(out); final StopWatch sw = new StopWatch(); try { IOUtils.writeString(fileName, dos); IOUtils.writeString(writeDirPath, dos); long nbytes = data.size(); dos.writeLong(nbytes); dos.writeBoolean(append); dos.writeBoolean(sync); if (handler == null) { dos.writeBoolean(false); } else { dos.writeBoolean(true); handler.writeAdditionalHeader(dos); } // send file using zero-copy send data.writeTo(out); if (LOG.isDebugEnabled()) { LOG.debug("Sent a file data '" + fileName + "' of " + nbytes + " bytes to " + dstSockAddr.toString() + " in " + sw.toString()); } if (sync) {// receive ack in sync mode long remoteRecieved = din.readLong(); if (remoteRecieved != nbytes) { throw new IllegalStateException( "Sent " + nbytes + " bytes, but remote node received " + remoteRecieved + " bytes"); } } } catch (FileNotFoundException e) { LOG.error(PrintUtils.prettyPrintStackTrace(e, -1)); throw e; } catch (IOException e) { LOG.error(PrintUtils.prettyPrintStackTrace(e, -1)); throw e; } finally { IOUtils.closeQuietly(din, dos); IOUtils.closeQuietly(channel); NetUtils.closeQuietly(socket); } }
From source file:org.csc.phynixx.loggersystem.logrecord.XADataLogger.java
private long recoverMessageSequenceId(byte[] bytes) { byte[] headerData = bytes; DataInputStream io = new DataInputStream(new ByteArrayInputStream(headerData)); try {// w w w .j av a2s. c om long messageSequenceId = io.readLong(); return messageSequenceId; } catch (IOException e) { throw new DelegatedRuntimeException(e); } }
From source file:ch.scythe.hsr.api.TimeTableAPI.java
private Date getCacheTimestamp() throws RequestException { Date cacheTimestamp = null;// w w w .j a va 2 s. c om DataInputStream inputStream = null; try { inputStream = new DataInputStream(context.openFileInput(TIMETABLE_CACHE_TIMESTAMP)); cacheTimestamp = new Date(inputStream.readLong()); } catch (FileNotFoundException e) { throw new RequestException(e); } catch (IOException e) { throw new RequestException(e); } finally { safeCloseStream(inputStream); } return cacheTimestamp; }
From source file:com.serenegiant.media.TLMediaEncoder.java
static TLMediaFrameHeader readHeader(final DataInputStream in, final TLMediaFrameHeader header) throws IOException { header.size = 0;//from ww w . ja v a2 s . co m header.sequence = in.readInt(); header.frameNumber = in.readInt(); // frame number header.presentationTimeUs = in.readLong(); header.size = in.readInt(); header.flags = in.readInt(); in.skipBytes(40); // long x 5 return header; }
From source file:org.apache.cassandra.db.ReadCommand.java
public ReadCommand deserialize(DataInputStream dis) throws IOException { String table = dis.readUTF(); String key = dis.readUTF();/*from www . ja va 2s .com*/ String columnFamily_column = dis.readUTF(); int start = dis.readInt(); int count = dis.readInt(); long sinceTimestamp = dis.readLong(); boolean isDigest = dis.readBoolean(); int size = dis.readInt(); List<String> columns = new ArrayList<String>(); for (int i = 0; i < size; ++i) { byte[] bytes = new byte[dis.readInt()]; dis.readFully(bytes); columns.add(new String(bytes)); } ReadCommand rm = null; if (columns.size() > 0) { rm = new ReadCommand(table, key, columnFamily_column, columns); } else if (sinceTimestamp > 0) { rm = new ReadCommand(table, key, columnFamily_column, sinceTimestamp); } else { rm = new ReadCommand(table, key, columnFamily_column, start, count); } rm.setDigestQuery(isDigest); return rm; }
From source file:pcap.application.PcapApplicationTest.java
/** * Test PcapApplication with little endian on entrency. * @throws java.lang.Exception/*from w ww . j a va 2s . c o m*/ */ @Test public void testPcapApplicationLittleEndian() throws Exception { System.out.println("Test resulting pcap file with little endian"); String pcapName = "testPcap" + PCAP_EX; String resultingPcapName = "test" + PCAP_EX; File pcap = createTempPCapLittleEndian(pcapName); final File resultingPcap = tempFolder.newFile(resultingPcapName); String[] myArgs = { OPTION_F, pcap.getAbsolutePath(), resultingPcap.getAbsolutePath() }; PcapCommandLineParser parser = new PcapCommandLineParser(myArgs); ApplicationHandler handler = new ApplicationHandler(parser.getOutFile()); PCapImportTask importTask = PCapHelper.createImportTask(parser.getInFile(), handler); importTask.init(); while (!importTask.isFinished()) { importTask.processNext(); } long[] expBin = { 0xa1b2c3d400020004L, 0x0000000000000000L, 0x0000ffff00000001L, 0x42c23479000871cdL, 0x000000080000004bL, 0x1234ffff0000121aL }; DataInputStream inputStream = new DataInputStream(new FileInputStream(resultingPcap)); int count = inputStream.available() / 8; long[] b = new long[count]; for (int i = 0; i < count; i++) { b[i] = inputStream.readLong(); } assertTrue(Arrays.equals(b, expBin)); }
From source file:pcap.application.PcapApplicationTest.java
/** * Test PcapApplication with big endian on entrency. * @throws Exception //from w w w . j ava 2 s .co m */ @Test public void testPcapApplicationBigEndian() throws Exception { System.out.println("Test resulting pcap file with big endian"); String pcapName = "testPcap" + PCAP_EX; String resultingPcapName = "test" + PCAP_EX; File pcap = createTempPCapBigEndian(pcapName); final File resultingPcap = tempFolder.newFile(resultingPcapName); String[] myArgs = { OPTION_F, pcap.getAbsolutePath(), resultingPcap.getAbsolutePath() }; PcapCommandLineParser parser = new PcapCommandLineParser(myArgs); ApplicationHandler handler = new ApplicationHandler(parser.getOutFile()); PCapImportTask importTask = PCapHelper.createImportTask(parser.getInFile(), handler); importTask.init(); while (!importTask.isFinished()) { importTask.processNext(); } long[] expBin = { 0xa1b2c3d400020004L, 0x0000000000000000L, 0x0000ffff00000001L, 0x42c23479000871cdL, 0x000000080000004bL, 0x1234ffff0000121aL }; DataInputStream inputStream = new DataInputStream(new FileInputStream(resultingPcap)); int count = inputStream.available() / 8; long[] b = new long[count]; for (int i = 0; i < count; i++) { b[i] = inputStream.readLong(); System.out.println(Long.toHexString(b[i])); } assertTrue(Arrays.equals(b, expBin)); }
From source file:com.quigley.zabbixj.agent.active.ActiveThread.java
private JSONObject getResponse(byte[] responseBytes) throws Exception { byte[] sizeBuffer = new byte[8]; int index = 0; for (int i = 12; i > 4; i--) { sizeBuffer[index++] = responseBytes[i]; }/*ww w. j a v a 2s . com*/ ByteArrayInputStream bais = new ByteArrayInputStream(sizeBuffer); DataInputStream dis = new DataInputStream(bais); long size = dis.readLong(); dis.close(); bais.close(); byte[] jsonBuffer = new byte[responseBytes.length - 13]; if (jsonBuffer.length != size) { throw new ZabbixException("Reported and actual buffer sizes differ!"); } index = 0; for (int i = 13; i < responseBytes.length; i++) { jsonBuffer[index++] = responseBytes[i]; } JSONObject response = new JSONObject(new String(jsonBuffer)); return response; }
From source file:org.structr.core.graph.SyncCommand.java
private static Object readObject(final DataInputStream inputStream, final byte type) throws IOException { switch (type) { case 0:/*from w w w. j a va 2 s .co m*/ case 1: return inputStream.readByte(); case 2: case 3: return inputStream.readShort(); case 4: case 5: return inputStream.readInt(); case 6: case 7: return inputStream.readLong(); case 8: case 9: return inputStream.readFloat(); case 10: case 11: return inputStream.readDouble(); case 12: case 13: return inputStream.readChar(); case 14: case 15: return new String(deserializeData(inputStream), "UTF-8"); // this doesn't work with very long strings //return inputStream.readUTF(); case 16: case 17: return inputStream.readBoolean(); } return null; }
From source file:com.facebook.infrastructure.db.Column.java
public void skip(DataInputStream dis) throws IOException { /* read the column name */ dis.readUTF();//from www . java 2 s . c om /* boolean indicating if the column is deleted */ dis.readBoolean(); /* timestamp associated with the column */ dis.readLong(); /* size of the column */ int size = dis.readInt(); dis.skip(size); }