Java Code Examples for com.google.common.io.LittleEndianDataOutputStream#write()
The following examples show how to use
com.google.common.io.LittleEndianDataOutputStream#write() .
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: StringPoolChunk.java From android-arscblamer with Apache License 2.0 | 6 votes |
@Override public byte[] toByteArray(int options) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); LittleEndianDataOutputStream payload = new LittleEndianDataOutputStream(baos); try { for (StringPoolSpan span : spans()) { byte[] encodedSpan = span.toByteArray(options); if (encodedSpan.length != StringPoolSpan.SPAN_LENGTH) { throw new IllegalStateException("Encountered a span of invalid length."); } payload.write(encodedSpan); } payload.writeInt(RES_STRING_POOL_SPAN_END); } finally { Closeables.close(payload, true); } return baos.toByteArray(); }
Example 2
Source File: KdbxSerializer.java From KeePassJava2 with Apache License 2.0 | 4 votes |
private static void writeStartBytes(KdbxHeader kdbxHeader, OutputStream encryptedOutputStream) throws IOException { LittleEndianDataOutputStream ledos = new LittleEndianDataOutputStream(encryptedOutputStream); ledos.write(kdbxHeader.getStreamStartBytes()); }
Example 3
Source File: KdbxSerializer.java From KeePassJava2 with Apache License 2.0 | 4 votes |
/** * Write a KdbxHeader to the output stream supplied. The header is updated with the * message digest of the written stream. * @param kdbxHeader the header to write and update * @param outputStream the output stream * @throws IOException on error */ public static void writeKdbxHeader(KdbxHeader kdbxHeader, OutputStream outputStream) throws IOException { MessageDigest messageDigest = Encryption.getMessageDigestInstance(); DigestOutputStream digestOutputStream = new DigestOutputStream(outputStream, messageDigest); LittleEndianDataOutputStream ledos = new LittleEndianDataOutputStream(digestOutputStream); // write the magic number ledos.writeInt(SIG1); ledos.writeInt(SIG2); // write a file version ledos.writeInt(FILE_VERSION_32); ledos.writeByte(HeaderType.CIPHER_ID); ledos.writeShort(16); byte[] b = new byte[16]; ByteBuffer bb = ByteBuffer.wrap(b); bb.putLong(kdbxHeader.getCipherUuid().getMostSignificantBits()); bb.putLong(8, kdbxHeader.getCipherUuid().getLeastSignificantBits()); ledos.write(b); ledos.writeByte(HeaderType.COMPRESSION_FLAGS); ledos.writeShort(4); ledos.writeInt(kdbxHeader.getCompressionFlags().ordinal()); ledos.writeByte(HeaderType.MASTER_SEED); ledos.writeShort(kdbxHeader.getMasterSeed().length); ledos.write(kdbxHeader.getMasterSeed()); ledos.writeByte(HeaderType.TRANSFORM_SEED); ledos.writeShort(kdbxHeader.getTransformSeed().length); ledos.write(kdbxHeader.getTransformSeed()); ledos.writeByte(HeaderType.TRANSFORM_ROUNDS); ledos.writeShort(8); ledos.writeLong(kdbxHeader.getTransformRounds()); ledos.writeByte(HeaderType.ENCRYPTION_IV); ledos.writeShort(kdbxHeader.getEncryptionIv().length); ledos.write(kdbxHeader.getEncryptionIv()); ledos.writeByte(HeaderType.PROTECTED_STREAM_KEY); ledos.writeShort(kdbxHeader.getProtectedStreamKey().length); ledos.write(kdbxHeader.getProtectedStreamKey()); ledos.writeByte(HeaderType.STREAM_START_BYTES); ledos.writeShort(kdbxHeader.getStreamStartBytes().length); ledos.write(kdbxHeader.getStreamStartBytes()); ledos.writeByte(HeaderType.INNER_RANDOM_STREAM_ID); ledos.writeShort(4); ledos.writeInt(kdbxHeader.getProtectedStreamAlgorithm().ordinal()); ledos.writeByte(HeaderType.END); ledos.writeShort(0); MessageDigest digest = digestOutputStream.getMessageDigest(); kdbxHeader.setHeaderHash(digest.digest()); }