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:org.apache.hadoop.hdfs.server.namenode.FSImageSerialization.java
static void writeINodeUnderConstruction(DataOutputStream out, INodeFileUnderConstruction cons, String path) throws IOException { writeString(path, out);/*from w ww. ja v a 2 s . c o m*/ out.writeLong(cons.getId()); out.writeShort(cons.getFileReplication()); out.writeLong(cons.getModificationTime()); out.writeLong(cons.getPreferredBlockSize()); writeBlocks(cons.getBlocks(), out); cons.getPermissionStatus().write(out); writeString(cons.getClientName(), out); writeString(cons.getClientMachine(), out); out.writeInt(0); // do not store locations of last block }
From source file:org.nuras.mcpha.Client.java
/** * Send command to device//from ww w .j a va 2 s. c om * * @param code * @param chan * @param data */ private static void sendCommand(long code, long chan, long data) throws IOException { logDebugMessage("sendCommand - code=" + code + ", chan=" + chan + ", data=" + data); DataOutputStream out = new DataOutputStream(deviceSocket.getOutputStream()); long b = (long) (code << SHIFT_CODE) | (validateChannel(chan) << SHIFT_CHAN) | data; out.writeLong(Long.reverseBytes(b)); }
From source file:Main.java
public static void writeSettings(String file, Object... objs) throws IOException { DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file), 1024)); try {/* w w w.j av a 2 s.c o m*/ out.writeInt(objs.length); for (Object obj : objs) { char cl; if (obj instanceof Byte) { cl = 'Y'; } else { cl = obj.getClass().getSimpleName().charAt(0); } out.writeChar(cl); if (obj instanceof String) { out.writeUTF((String) obj); } else if (obj instanceof Float) { out.writeFloat((Float) obj); } else if (obj instanceof Double) { out.writeDouble((Double) obj); } else if (obj instanceof Integer) { out.writeInt((Integer) obj); } else if (obj instanceof Long) { out.writeLong((Long) obj); } else if (obj instanceof Boolean) { out.writeBoolean((Boolean) obj); } else { throw new IllegalStateException("Unsupported type"); } } } finally { out.close(); } }
From source file:org.apache.hadoop.hdfs.server.namenode.FSImageSerialization.java
/** * Write an array of blocks as compactly as possible. This uses * delta-encoding for the generation stamp and size, following * the principle that genstamp increases relatively slowly, * and size is equal for all but the last block of a file. *//*from www. ja v a 2s . c om*/ public static void writeCompactBlockArray(Block[] blocks, DataOutputStream out) throws IOException { WritableUtils.writeVInt(out, blocks.length); Block prev = null; for (Block b : blocks) { long szDelta = b.getNumBytes() - (prev != null ? prev.getNumBytes() : 0); long gsDelta = b.getGenerationStamp() - (prev != null ? prev.getGenerationStamp() : 0); out.writeLong(b.getBlockId()); // blockid is random WritableUtils.writeVLong(out, szDelta); WritableUtils.writeVLong(out, gsDelta); prev = b; } }
From source file:edu.umn.cs.spatialHadoop.indexing.RTreeLocalIndexer.java
@Override public void buildLocalIndex(File nonIndexedFile, Path outputIndexedFile, Shape shape) throws IOException, InterruptedException { // Read all data of the written file in memory byte[] cellData = new byte[(int) nonIndexedFile.length()]; InputStream cellIn = new BufferedInputStream(new FileInputStream(nonIndexedFile)); cellIn.read(cellData);/*from w w w . j a v a2s . c o m*/ cellIn.close(); // Build an RTree over the elements read from file // Create the output file FileSystem outFS = outputIndexedFile.getFileSystem(conf); DataOutputStream cellStream = outFS.create(outputIndexedFile); cellStream.writeLong(SpatialSite.RTreeFileMarker); int degree = 4096 / RTree.NodeSize; boolean fastAlgorithm = conf.get(SpatialSite.RTREE_BUILD_MODE, "fast").equals("fast"); RTree.bulkLoadWrite(cellData, 0, cellData.length, degree, cellStream, shape.clone(), fastAlgorithm); cellStream.close(); }
From source file:org.apache.geode.internal.cache.tier.sockets.MessageIdExtractorTest.java
private byte[] byteArrayFromIds(Long connectionId, Long uniqueId) throws IOException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); DataOutputStream dis = new DataOutputStream(byteArrayOutputStream); dis.writeLong(connectionId); dis.writeLong(uniqueId);//from w ww. j av a2 s . c o m dis.flush(); return byteArrayOutputStream.toByteArray(); }
From source file:com.yattatech.io.ShalomFileWriter.java
public boolean write(Seminary seminary) { final String path = seminary.getFilePath(); final String json = new Gson().toJson(seminary); boolean sucess = true; DataOutputStream out = null; try {/*from w ww . java 2s. c o m*/ out = new DataOutputStream(new FileOutputStream(path)); out.writeLong(ChecksumCalculator.calculateChecksum(json)); out.writeUTF("\n"); out.writeUTF(json); } catch (IOException ioe) { LOGGER.log(Level.SEVERE, ioe.getMessage()); sucess = false; } finally { IOUtils.closeQuietly(out); return sucess; } }
From source file:mitm.common.security.crypto.PBEncryptedStreamParameters.java
/** * Returns the encoded form of PBEncryptionParameters. *///from w w w . j av a2s . c o m public byte[] getEncoded() throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(bos); out.writeLong(serialVersionUID); out.writeUTF(algorithm); out.writeInt(salt.length); out.write(salt); out.writeInt(iterationCount); return bos.toByteArray(); }
From source file:mitm.common.security.password.PBEncryptionParameters.java
/** * Returns the encoded form of PBEncryptionParameters. *///ww w . jav a 2s.co m public byte[] getEncoded() throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(bos); out.writeLong(serialVersionUID); out.writeInt(salt.length); out.write(salt); out.writeInt(iterationCount); out.writeInt(encryptedData.length); out.write(encryptedData); return bos.toByteArray(); }
From source file:org.axonframework.eventstore.fs.FileSystemSnapshotEventWriter.java
/** * Writes the given snapshotEvent to the {@link #snapshotEventFile}. * Prepends a long value to the event in the file indicating the bytes to skip when reading the {@link #eventFile}. * * @param snapshotEvent The snapshot to write to the {@link #snapshotEventFile} *///from w w w .j a v a2s.c o m public void writeSnapshotEvent(DomainEventMessage snapshotEvent) { try { long offset = calculateOffset(snapshotEvent); DataOutputStream dataOutputStream = new DataOutputStream(snapshotEventFile); dataOutputStream.writeLong(offset); FileSystemEventMessageWriter eventMessageWriter = new FileSystemEventMessageWriter(dataOutputStream, eventSerializer); eventMessageWriter.writeEventMessage(snapshotEvent); } catch (IOException e) { throw new EventStoreException("Error writing a snapshot event due to an IO exception", e); } finally { IOUtils.closeQuietly(snapshotEventFile); } }