Java Code Examples for java.io.DataOutputStream#writeLong()
The following examples show how to use
java.io.DataOutputStream#writeLong() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NumberConstantData.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
/** * Write the constant to the output stream */ void write(Environment env, DataOutputStream out, ConstantPool tab) throws IOException { if (num instanceof Integer) { out.writeByte(CONSTANT_INTEGER); out.writeInt(num.intValue()); } else if (num instanceof Long) { out.writeByte(CONSTANT_LONG); out.writeLong(num.longValue()); } else if (num instanceof Float) { out.writeByte(CONSTANT_FLOAT); out.writeFloat(num.floatValue()); } else if (num instanceof Double) { out.writeByte(CONSTANT_DOUBLE); out.writeDouble(num.doubleValue()); } }
Example 2
Source File: DataStreamDemo.java From Java with Artistic License 2.0 | 6 votes |
private static void write() throws IOException { // DataOutputStream(OutputStream out) DataOutputStream dos = new DataOutputStream(new FileOutputStream( "dos.txt")); // д���� dos.writeByte(1); dos.writeShort(10); dos.writeInt(100); dos.writeLong(1000); dos.writeFloat(1.1f); dos.writeDouble(2.2); dos.writeChar('a'); dos.writeBoolean(true); // �ͷ���Դ dos.close(); }
Example 3
Source File: NumberConstantData.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Write the constant to the output stream */ void write(Environment env, DataOutputStream out, ConstantPool tab) throws IOException { if (num instanceof Integer) { out.writeByte(CONSTANT_INTEGER); out.writeInt(num.intValue()); } else if (num instanceof Long) { out.writeByte(CONSTANT_LONG); out.writeLong(num.longValue()); } else if (num instanceof Float) { out.writeByte(CONSTANT_FLOAT); out.writeFloat(num.floatValue()); } else if (num instanceof Double) { out.writeByte(CONSTANT_DOUBLE); out.writeDouble(num.doubleValue()); } }
Example 4
Source File: Ext2FileSystem.java From birt with Eclipse Public License 1.0 | 5 votes |
private void writeHeader( ) throws IOException { ByteArrayOutputStream bytes = new ByteArrayOutputStream( BLOCK_SIZE ); DataOutputStream out = new DataOutputStream( bytes ); out.writeLong( EXT2_MAGIC_TAG ); out.writeInt( EXT2_VERSION_0 ); out.writeInt( BLOCK_SIZE ); rf.seek( 0 ); rf.write( bytes.toByteArray( ) ); }
Example 5
Source File: UtxoTrieNode.java From jelectrum with MIT License | 5 votes |
/** * Serialize to a byte string */ public ByteString serialize() { try { ByteArrayOutputStream b_out = new ByteArrayOutputStream(); DataOutputStream d_out = new DataOutputStream(b_out); d_out.writeLong(serialVersionUID); SerialUtil.writeString(d_out, prefix); d_out.writeInt(springs.size()); for(Map.Entry<String, Sha256Hash> me : springs.entrySet()) { SerialUtil.writeString(d_out, me.getKey()); Sha256Hash hash = me.getValue(); if (hash == null) hash = hash_null; d_out.write(hash.getBytes()); } d_out.flush(); return ByteString.copyFrom(b_out.toByteArray()); } catch(java.io.IOException e) { throw new RuntimeException(e); } }
Example 6
Source File: BlobBackupHelper.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * New overall state record */ private void writeBackupState(ArrayMap<String, Long> state, ParcelFileDescriptor stateFile) { try { FileOutputStream fos = new FileOutputStream(stateFile.getFileDescriptor()); // We explicitly don't close 'out' because we must not close the backing fd. // The FileOutputStream will not close it implicitly. @SuppressWarnings("resource") DataOutputStream out = new DataOutputStream(fos); out.writeInt(mCurrentBlobVersion); final int N = (state != null) ? state.size() : 0; out.writeInt(N); for (int i = 0; i < N; i++) { final String key = state.keyAt(i); final long checksum = state.valueAt(i).longValue(); if (DEBUG) { Log.i(TAG, " writing key " + key + " checksum = " + checksum); } out.writeUTF(key); out.writeLong(checksum); } } catch (IOException e) { Log.e(TAG, "Unable to write updated state", e); } }
Example 7
Source File: BloomFilter.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
/** * Writes this {@code BloomFilter} to an output stream, with a custom format (not Java * serialization). This has been measured to save at least 400 bytes compared to regular * serialization. * * <p>Use {@linkplain #readFrom(InputStream, Funnel)} to reconstruct the written BloomFilter. */ public void writeTo(OutputStream out) throws IOException { // Serial form: // 1 signed byte for the strategy // 1 unsigned byte for the number of hash functions // 1 big endian int, the number of longs in our bitset // N big endian longs of our bitset DataOutputStream dout = new DataOutputStream(out); dout.writeByte(SignedBytes.checkedCast(strategy.ordinal())); dout.writeByte(UnsignedBytes.checkedCast(numHashFunctions)); // note: checked at the c'tor dout.writeInt(bits.data.length); for (long value : bits.data) { dout.writeLong(value); } }
Example 8
Source File: Sign.java From tectonicus with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void writeTo(DataOutputStream dest) throws Exception { dest.writeInt(blockData); dest.writeLong(position.x); dest.writeLong(position.y); dest.writeLong(position.z); for (int i=0; i<text.length; i++) dest.writeUTF(text[i]); }
Example 9
Source File: LongBuffer.java From netbeans with Apache License 2.0 | 5 votes |
void writeToStream(DataOutputStream out) throws IOException { out.writeInt(bufferSize); out.writeInt(readOffset); out.writeInt(longs); out.writeInt(buffer.length); out.writeBoolean(useBackingFile); if (useBackingFile) { out.writeUTF(backingFile.getAbsolutePath()); } else { for (int i=0; i<bufferSize; i++) { out.writeLong(buffer[i]); } } }
Example 10
Source File: CodeRegionResultsSnapshot.java From netbeans with Apache License 2.0 | 5 votes |
public void writeToStream(DataOutputStream out) throws IOException { super.writeToStream(out); out.writeLong(timerCountsInSecond); out.writeInt(rawData.length); for (int i = 0; i < rawData.length; i++) { out.writeLong(rawData[i]); } }
Example 11
Source File: RecordStoreImpl.java From J2ME-Loader with Apache License 2.0 | 5 votes |
public void writeHeader(DataOutputStream dos) throws IOException { dos.write(fileIdentifier); dos.write(versionMajor); dos.write(versionMinor); dos.write(0); // Encrypted flag dos.writeUTF(recordStoreName); dos.writeLong(lastModified); dos.writeInt(version); dos.writeInt(0); // TODO AuthMode dos.writeByte(0); // TODO Writable dos.writeInt(size); }
Example 12
Source File: INode.java From RDFS with Apache License 2.0 | 5 votes |
public InputStream serialize() throws IOException { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(bytes); out.writeByte(fileType.ordinal()); if (isFile()) { out.writeInt(blocks.length); for (int i = 0; i < blocks.length; i++) { out.writeLong(blocks[i].getId()); out.writeLong(blocks[i].getLength()); } } out.close(); return new ByteArrayInputStream(bytes.toByteArray()); }
Example 13
Source File: ObjectInputStreamInstantiator.java From objenesis with Apache License 2.0 | 5 votes |
public MockStream(Class<?> clazz) { this.pointer = 0; this.sequence = 0; this.data = HEADER; // (byte) TC_OBJECT // (byte) TC_CLASSDESC // (short length) // (byte * className.length) // (long)serialVersionUID // (byte) SC_SERIALIZABLE // (short)0 <fields> // TC_ENDBLOCKDATA // TC_NULL ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); DataOutputStream dout = new DataOutputStream(byteOut); try { dout.writeByte(ObjectStreamConstants.TC_OBJECT); dout.writeByte(ObjectStreamConstants.TC_CLASSDESC); dout.writeUTF(clazz.getName()); dout.writeLong(ObjectStreamClass.lookup(clazz).getSerialVersionUID()); dout.writeByte(ObjectStreamConstants.SC_SERIALIZABLE); dout.writeShort((short) 0); // Zero fields dout.writeByte(ObjectStreamConstants.TC_ENDBLOCKDATA); dout.writeByte(ObjectStreamConstants.TC_NULL); } catch(IOException e) { throw new Error("IOException: " + e.getMessage()); } this.FIRST_DATA = byteOut.toByteArray(); buffers = new byte[][] {HEADER, FIRST_DATA, REPEATING_DATA}; }
Example 14
Source File: StandardTocWriter.java From nifi with Apache License 2.0 | 5 votes |
@Override public void addBlockOffset(final long offset, final long firstEventId) throws IOException { final BufferedOutputStream bos = new BufferedOutputStream(fos); final DataOutputStream dos = new DataOutputStream(bos); dos.writeLong(offset); dos.writeLong(firstEventId); dos.flush(); index++; logger.debug("Adding block {} at offset {}", index, offset); if ( alwaysSync ) { sync(); } }
Example 15
Source File: RootInfo.java From FireFiles with Apache License 2.0 | 5 votes |
@Override public void write(DataOutputStream out) throws IOException { out.writeInt(VERSION_DROP_TYPE); DurableUtils.writeNullableString(out, authority); DurableUtils.writeNullableString(out, rootId); out.writeInt(flags); out.writeInt(icon); DurableUtils.writeNullableString(out, title); DurableUtils.writeNullableString(out, summary); DurableUtils.writeNullableString(out, documentId); out.writeLong(availableBytes); out.writeLong(totalBytes); DurableUtils.writeNullableString(out, mimeTypes); DurableUtils.writeNullableString(out, path); }
Example 16
Source File: NumberList.java From netbeans with Apache License 2.0 | 4 votes |
void writeToStream(DataOutputStream out) throws IOException { out.writeUTF(dataFile.getAbsolutePath()); out.writeInt(numberSize); out.writeLong(blocks); out.writeBoolean(buf != null); }
Example 17
Source File: SelfByteCodeCompiler.java From BotLibre with Eclipse Public License 1.0 | 4 votes |
/** * Parse the state and any referenced states or variables. */ public Vertex parseState(TextStream stream, Map<String, Map<String, Vertex>> elements, boolean debug, Network network) { try { List<String> comments = null; Vertex state = parseElement(stream, elements, debug, network); BinaryData byteCode = new BinaryData(); ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); DataOutputStream dataStream = new DataOutputStream(byteStream); stream.skipWhitespace(); ensureNext('{', stream); stream.skipWhitespace(); String element = stream.peekWord(); while (!("}".equals(element))) { if (element == null) { throw new SelfParseException("Unexpected end of state, missing '}'", stream); } element = element.toLowerCase(); if (element.equals(CASE)) { parseCaseByteCode(stream, dataStream, elements, debug, network); } else if (element.equals(PATTERN)) { parsePatternByteCode(stream, dataStream, elements, debug, network); } else if (element.equals(STATE)) { parseState(stream, elements, debug, network); } else if (element.equals(VAR) || element.equals(VARIABLE)) { parseVariable(stream, elements, debug, network); } else if (element.equals(QUOTIENT) || element.equals(ANSWER)) { parseQuotientByteCode(stream, dataStream, elements, debug, network); } else if (element.equals(EQUATION) || element.equals(FUNCTION)) { parseEquation(stream, elements, debug, network); } else if (element.equals(DO)) { parseDoByteCode(stream, dataStream, elements, debug, network); } else if (element.equals(GOTO)) { parseGotoByteCode(stream, dataStream, elements, debug, network); } else if (element.equals(PUSH)) { parsePushByteCode(stream, dataStream, elements, debug, network); } else if (element.equals(RETURN)) { parseReturnByteCode(stream, dataStream, elements, debug, network); } else if (element.equals("/")) { comments = getComments(stream); if (comments.isEmpty()) { throw new SelfParseException("Unknown element: " + element, stream); } } else { throw new SelfParseException("Unknown element: " + element, stream); } element = stream.peekWord(); } ensureNext('}', stream); dataStream.writeLong(0l); byteCode.setBytes(byteStream.toByteArray()); state.setData(byteCode); network.addVertex(state); return state; } catch (IOException exception) { throw new SelfParseException("IO Error", stream, exception); } }
Example 18
Source File: CommitRecordSerializer.java From database with GNU General Public License v2.0 | 3 votes |
public byte[] serialize(ICommitRecord commitRecord) { final long timestamp = commitRecord.getTimestamp(); final long commitCounter = commitRecord.getCommitCounter(); final int n = commitRecord.getRootAddrCount(); try { ByteArrayOutputStream baos = new ByteArrayOutputStream( n * Bytes.SIZEOF_LONG); DataOutputStream dos = new DataOutputStream(baos); dos.writeInt(VERSION0); dos.writeLong(timestamp); dos.writeLong(commitCounter); LongPacker.packLong((DataOutput)dos, n); for(int i=0; i<n; i++) { dos.writeLong(commitRecord.getRootAddr(i)); // LongPacker.packLong(dos, commitRecord.getRootAddr(i)); } return baos.toByteArray(); } catch (IOException ex) { throw new RuntimeException(ex); } }
Example 19
Source File: BitVectors.java From database with GNU General Public License v2.0 | 3 votes |
/** Writes quickly a bit vector to a {@link DataOutputStream}. * * <p>This method writes a bit vector in a simple format: first, a long representing the length. * Then, as many longs as necessary to write the bits in the bit vectors (i.e., * {@link LongArrayBitVector#numWords(long)} of the bit vector length), obtained via {@link BitVector#getLong(long, long)}. * * <p>The main purpose of this function is to support {@link OfflineIterable} (see {@link #OFFLINE_SERIALIZER}). * * @param v a bit vector. * @param dos a data output stream. */ public static void writeFast( final BitVector v, final DataOutputStream dos ) throws IOException { final long length = v.length(); final long l = length - length % Long.SIZE; dos.writeLong( length ); long i; for( i = 0; i < l; i += Long.SIZE ) dos.writeLong( v.getLong( i, i + Long.SIZE ) ); if ( i < length ) dos.writeLong( v.getLong( i, length ) ); }
Example 20
Source File: DHTUDPPacketRequest.java From TorrentEngine with GNU General Public License v3.0 | 2 votes |
public void serialise( DataOutputStream os ) throws IOException { super.serialise(os); // add to this and you need to amend HEADER_SIZE above os.writeByte( protocol_version ); if ( protocol_version >= DHTTransportUDP.PROTOCOL_VERSION_VENDOR_ID ){ os.writeByte( DHTTransportUDP.VENDOR_ID_ME ); } if ( protocol_version >= DHTTransportUDP.PROTOCOL_VERSION_NETWORKS ){ os.writeInt( network ); } if ( protocol_version >= DHTTransportUDP.PROTOCOL_VERSION_FIX_ORIGINATOR ){ // originator version os.writeByte( getTransport().getProtocolVersion()); } try{ DHTUDPUtils.serialiseAddress( os, originator_address ); }catch( DHTTransportException e ){ throw( new IOException( e.getMessage())); } os.writeInt( originator_instance_id ); os.writeLong( originator_time ); if ( protocol_version >= DHTTransportUDP.PROTOCOL_VERSION_PACKET_FLAGS ){ os.writeByte( flags ); } if ( protocol_version >= DHTTransportUDP.PROTOCOL_VERSION_PACKET_FLAGS2 ){ os.writeByte( flags2 ); } }