private void writeTrailer(Path trailerPath, FixedFileTrailer t, byte[] useBytesInstead) throws IOException { assert (t == null) != (useBytesInstead == null); // Expect one non-null. FSDataOutputStream fsdos = fs.create(trailerPath); fsdos.write(135); // to make deserializer's job less trivial if (useBytesInstead != null) { fsdos.write(useBytesInstead); } else { t.serialize(fsdos); } fsdos.close(); }
protected void finishClose(FixedFileTrailer trailer) throws IOException { // Write out encryption metadata before finalizing if we have a valid crypto context Encryption.Context cryptoContext = hFileContext.getEncryptionContext(); if (cryptoContext != Encryption.Context.NONE) { // Wrap the context's key and write it as the encryption metadata, the wrapper includes // all information needed for decryption trailer.setEncryptionKey(EncryptionUtil.wrapKey(cryptoContext.getConf(), cryptoContext.getConf().get(HConstants.CRYPTO_MASTERKEY_NAME_CONF_KEY, User.getCurrent().getShortName()), cryptoContext.getKey())); } // Now we can finish the close trailer.setMetaIndexCount(metaNames.size()); trailer.setTotalUncompressedBytes(totalUncompressedBytes+ trailer.getTrailerSize()); trailer.setEntryCount(entryCount); trailer.setCompressionCodec(hFileContext.getCompression()); long startTime = System.currentTimeMillis(); trailer.serialize(outputStream); HFile.updateWriteLatency(System.currentTimeMillis() - startTime); if (closeOutputStream) { outputStream.close(); outputStream = null; } } }
t.serialize(dos); dos.flush(); assertEquals(dos.size(), FixedFileTrailer.getTrailerSize(version));
private void writeTrailer(Path trailerPath, FixedFileTrailer t, byte[] useBytesInstead) throws IOException { assert (t == null) != (useBytesInstead == null); // Expect one non-null. FSDataOutputStream fsdos = fs.create(trailerPath); fsdos.write(135); // to make deserializer's job less trivial if (useBytesInstead != null) { fsdos.write(useBytesInstead); } else { t.serialize(fsdos); } fsdos.close(); }
private static int[] computeTrailerSizeByVersion() { int versionToSize[] = new int[HFile.MAX_FORMAT_VERSION + 1]; for (int version = MIN_FORMAT_VERSION; version <= MAX_FORMAT_VERSION; ++version) { FixedFileTrailer fft = new FixedFileTrailer(version, HFileBlock.MINOR_VERSION_NO_CHECKSUM); DataOutputStream dos = new DataOutputStream(new NullOutputStream()); try { fft.serialize(dos); } catch (IOException ex) { // The above has no reason to fail. throw new RuntimeException(ex); } versionToSize[version] = dos.size(); } return versionToSize; }
/** * Sets remaining trailer fields, writes the trailer to disk, and optionally * closes the output stream. */ protected void finishClose(FixedFileTrailer trailer) throws IOException { trailer.setMetaIndexCount(metaNames.size()); trailer.setTotalUncompressedBytes(totalUncompressedBytes+ trailer.getTrailerSize()); trailer.setEntryCount(entryCount); trailer.setCompressionCodec(compressAlgo); trailer.serialize(outputStream); if (closeOutputStream) { outputStream.close(); outputStream = null; } }
/** * Sets remaining trailer fields, writes the trailer to disk, and optionally * closes the output stream. */ protected void finishClose(FixedFileTrailer trailer) throws IOException { trailer.setMetaIndexCount(metaNames.size()); trailer.setTotalUncompressedBytes(totalUncompressedBytes+ trailer.getTrailerSize()); trailer.setEntryCount(entryCount); trailer.setCompressionCodec(hFileContext.getCompression()); trailer.serialize(outputStream); if (closeOutputStream) { outputStream.close(); outputStream = null; } }
t.serialize(dos); dos.flush(); assertEquals(dos.size(), FixedFileTrailer.getTrailerSize(version));