List of usage examples for java.io DataOutputStream writeLong
public final void writeLong(long v) throws IOException
long
to the underlying output stream as eight bytes, high byte first. From source file:com.ebay.nest.io.sede.lazy.LazyUtils.java
/** * Write out a binary representation of a PrimitiveObject to a byte stream. * * @param out ByteStream.Output, an unsynchronized version of ByteArrayOutputStream, used as a * backing buffer for the the DataOutputStream * @param o the PrimitiveObject/*from ww w .ja v a2 s .co m*/ * @param oi the PrimitiveObjectInspector * @throws IOException on error during the write operation */ public static void writePrimitive(OutputStream out, Object o, PrimitiveObjectInspector oi) throws IOException { DataOutputStream dos = new DataOutputStream(out); try { switch (oi.getPrimitiveCategory()) { case BOOLEAN: boolean b = ((BooleanObjectInspector) oi).get(o); dos.writeBoolean(b); break; case BYTE: byte bt = ((ByteObjectInspector) oi).get(o); dos.writeByte(bt); break; case SHORT: short s = ((ShortObjectInspector) oi).get(o); dos.writeShort(s); break; case INT: int i = ((IntObjectInspector) oi).get(o); dos.writeInt(i); break; case LONG: long l = ((LongObjectInspector) oi).get(o); dos.writeLong(l); break; case FLOAT: float f = ((FloatObjectInspector) oi).get(o); dos.writeFloat(f); break; case DOUBLE: double d = ((DoubleObjectInspector) oi).get(o); dos.writeDouble(d); break; default: throw new RuntimeException("Hive internal error."); } } finally { // closing the underlying ByteStream should have no effect, the data should still be // accessible dos.close(); } }
From source file:edu.umn.cs.spatialHadoop.core.RTreeGridRecordWriter.java
/** * Closes a cell by writing all outstanding objects and closing current file. * Then, the file is read again, an RTree is built on top of it and, finally, * the file is written again with the RTree built. */// ww w . jav a 2s . c o m @Override protected Path flushAllEntries(Path intermediateCellPath, OutputStream intermediateCellStream, Path finalCellPath) throws IOException { // Close stream to current intermediate file. intermediateCellStream.close(); // Read all data of the written file in memory byte[] cellData = new byte[(int) new File(intermediateCellPath.toUri().getPath()).length()]; InputStream cellIn = new FileInputStream(intermediateCellPath.toUri().getPath()); cellIn.read(cellData); cellIn.close(); // Build an RTree over the elements read from file // It should create a new stream DataOutputStream cellStream = (DataOutputStream) createFinalCellStream(finalCellPath); cellStream.writeLong(SpatialSite.RTreeFileMarker); int degree = 4096 / RTree.NodeSize; RTree.bulkLoadWrite(cellData, 0, cellData.length, degree, cellStream, stockObject.clone(), fastRTree); cellStream.close(); cellData = null; // To allow GC to collect it return finalCellPath; }
From source file:com.csipsimple.backup.SipProfilesHelper.java
@Override public void writeNewStateDescription(ParcelFileDescriptor newState) { long fileModified = databaseFile.lastModified(); try {// w w w . j a v a 2 s . co m FileOutputStream outstream = new FileOutputStream(newState.getFileDescriptor()); DataOutputStream out = new DataOutputStream(outstream); out.writeLong(fileModified); out.close(); } catch (IOException e) { Log.e(THIS_FILE, "Cannot manage final local backup state", e); } }
From source file:org.nuxeo.osgi.BundleIdGenerator.java
public synchronized void store(File file) throws IOException { DataOutputStream out = null; try {//from w w w . j a va 2s.co m out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file))); out.writeLong(count); int size = ids.size(); out.writeInt(size); for (Map.Entry<String, Long> entry : ids.entrySet()) { out.writeUTF(entry.getKey()); out.writeLong(entry.getValue()); } } finally { if (out != null) { out.close(); } } }
From source file:org.apache.tez.examples.TopKDataGen.java
private UserPayload createPayload(long streamOutputFileSize, int extraColumns) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(bos); dos.writeLong(streamOutputFileSize); dos.writeInt(extraColumns);//from ww w . ja v a2s. c o m dos.close(); bos.close(); ByteBuffer buffer = ByteBuffer.wrap(bos.toByteArray()); return UserPayload.create(buffer); }
From source file:de.iritgo.aktario.jdbc.JDBCIDGenerator.java
/** * Write the object attributes to an output stream. * * @param stream The output stream./*w w w . ja v a 2 s.co m*/ */ public void writeObject(OutputStream stream) throws IOException { DataOutputStream dataStream = new DataOutputStream(stream); dataStream.writeLong(id); }
From source file:com.ricemap.spateDB.core.RTreeGridRecordWriter.java
/** * Closes a cell by writing all outstanding objects and closing current file. * Then, the file is read again, an RTree is built on top of it and, finally, * the file is written again with the RTree built. *//* w ww . jav a 2s.co m*/ @Override protected Path flushAllEntries(Path intermediateCellPath, OutputStream intermediateCellStream, Path finalCellPath) throws IOException { // Close stream to current intermediate file. intermediateCellStream.close(); // Read all data of the written file in memory byte[] cellData = new byte[(int) new File(intermediateCellPath.toUri().getPath()).length()]; InputStream cellIn = new FileInputStream(intermediateCellPath.toUri().getPath()); cellIn.read(cellData); cellIn.close(); // Build an RTree over the elements read from file RTree<S> rtree = new RTree<S>(); rtree.setStockObject(stockObject); // It should create a new stream DataOutputStream cellStream = (DataOutputStream) createFinalCellStream(finalCellPath); cellStream.writeLong(SpatialSite.RTreeFileMarker); int degree = 4096 / RTree.NodeSize; rtree.bulkLoadWrite(cellData, 0, cellData.length, degree, cellStream, fastRTree, columnarStorage); cellStream.close(); cellData = null; // To allow GC to collect it return finalCellPath; }
From source file:gridool.util.xfer.RecievedFileWriter.java
public final void handleRequest(@Nonnull final SocketChannel inChannel, @Nonnull final Socket socket) throws IOException { final StopWatch sw = new StopWatch(); if (!inChannel.isBlocking()) { inChannel.configureBlocking(true); }/*from w w w . j a v a2 s .c o m*/ InputStream in = socket.getInputStream(); DataInputStream dis = new DataInputStream(in); String fname = IOUtils.readString(dis); String dirPath = IOUtils.readString(dis); long len = dis.readLong(); boolean append = dis.readBoolean(); boolean ackRequired = dis.readBoolean(); boolean hasAdditionalHeader = dis.readBoolean(); if (hasAdditionalHeader) { readAdditionalHeader(dis, fname, dirPath, len, append, ackRequired); } final File file; if (dirPath == null) { file = new File(baseDir, fname); } else { File dir = FileUtils.resolvePath(baseDir, dirPath); file = new File(dir, fname); } preFileAppend(file, append); final FileOutputStream dst = new FileOutputStream(file, append); final String fp = file.getAbsolutePath(); final ReadWriteLock filelock = accquireLock(fp, locks); final FileChannel fileCh = dst.getChannel(); final long startPos = file.length(); try { NIOUtils.transferFully(inChannel, 0, len, fileCh); // REVIEWME really an atomic operation? } finally { IOUtils.closeQuietly(fileCh, dst); releaseLock(fp, filelock, locks); postFileAppend(file, startPos, len); } if (ackRequired) { OutputStream out = socket.getOutputStream(); DataOutputStream dos = new DataOutputStream(out); dos.writeLong(len); postAck(file, startPos, len); } if (LOG.isDebugEnabled()) { SocketAddress remoteAddr = socket.getRemoteSocketAddress(); LOG.debug("Received a " + (append ? "part of file '" : "file '") + file.getAbsolutePath() + "' of " + len + " bytes from " + remoteAddr + " in " + sw.toString()); } }
From source file:xbird.util.xfer.RecievedFileWriter.java
public final void handleRequest(@Nonnull final SocketChannel inChannel, @Nonnull final Socket socket) throws IOException { final StopWatch sw = new StopWatch(); if (!inChannel.isBlocking()) { inChannel.configureBlocking(true); }/*from w ww . j a v a2 s . com*/ InputStream in = socket.getInputStream(); DataInputStream dis = new DataInputStream(in); String fname = IOUtils.readString(dis); String dirPath = IOUtils.readString(dis); long len = dis.readLong(); boolean append = dis.readBoolean(); boolean ackRequired = dis.readBoolean(); boolean hasAdditionalHeader = dis.readBoolean(); if (hasAdditionalHeader) { readAdditionalHeader(dis, fname, dirPath, len, append, ackRequired); } final File file; if (dirPath == null) { file = new File(baseDir, fname); } else { File dir = FileUtils.resolvePath(baseDir, dirPath); file = new File(dir, fname); } preFileAppend(file, append); final FileOutputStream dst = new FileOutputStream(file, append); final String fp = file.getAbsolutePath(); final ReadWriteLock filelock = accquireLock(fp, locks); final FileChannel fileCh = dst.getChannel(); final long startPos = file.length(); try { NIOUtils.transferFullyFrom(inChannel, 0, len, fileCh); // REVIEWME really an atomic operation? } finally { IOUtils.closeQuietly(fileCh, dst); releaseLock(fp, filelock, locks); postFileAppend(file, startPos, len); } if (ackRequired) { OutputStream out = socket.getOutputStream(); DataOutputStream dos = new DataOutputStream(out); dos.writeLong(len); postAck(file, startPos, len); } if (LOG.isDebugEnabled()) { SocketAddress remoteAddr = socket.getRemoteSocketAddress(); LOG.debug("Received a " + (append ? "part of file '" : "file '") + file.getAbsolutePath() + "' of " + len + " bytes from " + remoteAddr + " in " + sw.toString()); } }
From source file:com.csipsimple.backup.SipSharedPreferencesHelper.java
@Override public void writeNewStateDescription(ParcelFileDescriptor newState) { long fileModified = 0; if (prefsFiles != null) { prefsFiles.lastModified();/* w ww . ja va2 s . co m*/ } try { FileOutputStream outstream = new FileOutputStream(newState.getFileDescriptor()); DataOutputStream out = new DataOutputStream(outstream); out.writeLong(fileModified); out.close(); } catch (IOException e) { Log.e(THIS_FILE, "Cannot manage final local backup state", e); } }