public static void writeEndBlob(DataOutputStream binaryBlobStream) throws IOException { writeBlobHeader(binaryBlobStream, BinaryBlob.BLOB_END, BinaryBlob.BLOB_END_VERSION, 0); }
private void getSnapshot(Bucket bucket, boolean addEndmarker) throws IOException, BinaryBlobAlreadyClosedException { if (_buckets.isEmpty()) return; if (_finalized) { throw new BinaryBlobAlreadyClosedException("Already closed (getting final data snapshot)"); } OutputStream out = bucket.getOutputStream(); try { for (int i=0,n=_buckets.size(); i<n;i++) { BucketTools.copyTo(_buckets.get(i), out, -1); } if (addEndmarker) { DataOutputStream dout = new DataOutputStream(out); BinaryBlob.writeEndBlob(dout); dout.flush(); } } finally { out.close(); } }
/** * Add a block to the binary blob. * @throws IOException * @throws BinaryBlobAlreadyClosedException */ public synchronized void addKey(ClientKeyBlock block, ClientContext context) throws IOException, BinaryBlobAlreadyClosedException { Key key = block.getKey(); if(_binaryBlobKeysAddedAlready.contains(key)) return; BinaryBlob.writeKey(getOutputStream(), block.getBlock(), key); _binaryBlobKeysAddedAlready.add(key); }
BinaryBlobInserter(Bucket blob, ClientPutter parent, RequestClient clientContext, boolean tolerant, short prioClass, InsertContext ctx, ClientContext context) throws IOException, BinaryBlobFormatException { logMINOR = Logger.shouldLog(LogLevel.MINOR, this); this.ctx = ctx; this.maxRetries = ctx.maxInsertRetries; this.consecutiveRNFsCountAsSuccess = ctx.consecutiveRNFsCountAsSuccess; this.parent = parent; this.clientContext = clientContext; this.errors = new FailureCodeTracker(true); this.realTimeFlag = clientContext.realTimeFlag(); DataInputStream dis = new DataInputStream(blob.getInputStream()); BlockSet blocks = new SimpleBlockSet(); try { BinaryBlob.readBinaryBlob(dis, blocks, tolerant); } finally { dis.close(); } ArrayList<MySendableInsert> myInserters = new ArrayList<MySendableInsert>(); int x=0; for(Key key: blocks.keys()) { KeyBlock block = blocks.get(key); MySendableInsert inserter = new MySendableInsert(x++, block, prioClass, getScheduler(block, context), clientContext); myInserters.add(inserter); } inserters = myInserters.toArray(new MySendableInsert[myInserters.size()]); parent.addMustSucceedBlocks(inserters.length); parent.notifyClients(context); }
private DataOutputStream getOutputStream() throws IOException, BinaryBlobAlreadyClosedException { if (_finalized) { throw new BinaryBlobAlreadyClosedException("Already finalized (getting final data) on "+this); } if (_stream_cache==null) { if (_isSingleBucket) { _stream_cache = new DataOutputStream(_out.getOutputStream()); } else { Bucket newBucket = _bf.makeBucket(-1); _buckets.add(newBucket); _stream_cache = new DataOutputStream(newBucket.getOutputStream()); } } if (!_started) { BinaryBlob.writeBinaryBlobHeader(_stream_cache); _started = true; } return _stream_cache; }
try { dis = new DataInputStream(new BufferedInputStream(new FileInputStream(temp))); BinaryBlob.readBinaryBlob(dis, blocks, true); } catch(FileNotFoundException e) { Logger.error(this, "Somebody deleted " + temp + " ? We lost the main jar (" + version + ") from " + toString + "!");
try { dis = new DataInputStream(temp.getInputStream()); BinaryBlob.readBinaryBlob(dis, blocks, true); } catch(FileNotFoundException e) { Logger.error(this, "Somebody deleted " + temp + " ? We lost the revocation certificate from " + source + "!");
public static void writeKey(DataOutputStream binaryBlobStream, KeyBlock block, Key key) throws IOException { byte[] keyData = key.getKeyBytes(); byte[] headers = block.getRawHeaders(); byte[] data = block.getRawData(); byte[] pubkey = block.getPubkeyBytes(); writeBlobHeader(binaryBlobStream, BLOB_BLOCK, BLOB_BLOCK_VERSION, 9+keyData.length+headers.length+data.length+(pubkey==null?0:pubkey.length)); binaryBlobStream.writeShort(block.getKey().getType()); binaryBlobStream.writeByte(keyData.length); binaryBlobStream.writeShort(headers.length); binaryBlobStream.writeShort(data.length); binaryBlobStream.writeShort(pubkey == null ? 0 : pubkey.length); binaryBlobStream.write(keyData); binaryBlobStream.write(headers); binaryBlobStream.write(data); if(pubkey != null) binaryBlobStream.write(pubkey); } static final short BLOB_BLOCK = 1;
private void finalizeBucket(boolean mark) throws IOException, BinaryBlobAlreadyClosedException { if (_finalized) throw new BinaryBlobAlreadyClosedException("Already finalized (closing blob - 2)."); if(logMINOR) Logger.minor(this, "Finalizing binary blob "+this, new Exception("debug")); if (!_isSingleBucket) { if (!mark && (_buckets.size()==1)) { return; } Bucket out = _bf.makeBucket(-1); getSnapshot(out, mark); for (int i=0,n=_buckets.size(); i<n;i++) { _buckets.get(i).free(); } if (mark) { out.setReadOnly(); } _buckets.clear(); _buckets.add(0, out); } else if (mark){ DataOutputStream out = new DataOutputStream(getOutputStream()); try { BinaryBlob.writeEndBlob(out); } finally { out.close(); } } if (mark) { _finalized = true; } }
SimpleBlockSet blocks = new SimpleBlockSet(); DataInputStream dis = new DataInputStream(blobBucket.getInputStream()); BinaryBlob.readBinaryBlob(dis, blocks, true); ctx2 = new FetchContext(ctx2, FetchContext.IDENTICAL_MASK, true, blocks); fw = new FetchWaiter(rc);