/** * Creates output stream for next block of data. * * @throws IOException serialization or block hash calculation error. */ private synchronized void nextBlockOutputStream() throws IOException { blockData = PithosSerializer.serializeFile(backupFile); container = pithosPath.getContainer(); hashAlgo = PithosFileSystem.getHadoopPithosConnector().getPithosContainerHashAlgorithm(container); try { blockHash = Utils.computeHash(blockData, hashAlgo); if (!PithosFileSystem.getHadoopPithosConnector() .pithosObjectBlockExists(container, blockHash)) { nextBlock = new PithosBlock(blockHash, bytesWrittenToBlock, blockData); bytesWrittenToBlock = 0; } } catch (NoSuchAlgorithmException e) { throw new IOException(e); } catch (Exception e) { Utils.dbgPrint("nextBlockOutputStream exception >", e.toString()); throw new IOException(e); } }
/** * Streams block to pithos when file buffer full. Prepares next file buffer. * * @throws IOException backupFile not found. */ private synchronized void endBlock() throws IOException { backupStream.close(); // - Load file bytes nextBlockOutputStream(); // - Append Pithos Block on the existing object PithosFileSystem.getHadoopPithosConnector() .appendPithosBlock( pithosPath.getContainer(), pithosPath.getObjectAbsolutePath(), nextBlock); // // Delete local backup, start new one // backupFile.delete(); backupFile = null; backupFile = newBackupFile(); backupStream = new FileOutputStream(backupFile); bytesWrittenToBlock = 0; }