private ClientGetter makeGetter(NodeClientCore core, Bucket ret) throws IOException { if (binaryBlob && ret == null) { ret = core.clientContext.getBucketFactory(persistence == Persistence.FOREVER).makeBucket(fctx.maxOutputLength); } return new ClientGetter(this, uri, fctx, priorityClass, binaryBlob ? new NullBucket() : ret, binaryBlob ? new BinaryBlobWriter(ret) : null, false, initialMetadata, extensionCheck); }
/** * finalize the return bucket * @throws IOException * @throws BinaryBlobAlreadyClosedException */ public void finalizeBucket() throws IOException, BinaryBlobAlreadyClosedException { if (_finalized) { throw new BinaryBlobAlreadyClosedException("Already finalized (closing blob)."); } finalizeBucket(true); }
public Bucket getBlobBucket() { return binaryBlobWriter.getFinalBucket(); }
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; } }
public synchronized void getSnapshot(Bucket bucket) throws IOException, BinaryBlobAlreadyClosedException { if (_buckets.isEmpty()) return; if (_finalized) { BucketTools.copy(_buckets.get(0), bucket); return; } getSnapshot(bucket, true); }
/** * 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); }
/** * Add a block to the binary blob. */ protected void addKeyToBinaryBlob(ClientKeyBlock block, ClientContext context) { if(binaryBlobWriter == null) return; synchronized(this) { if(finished) { if(logMINOR) Logger.minor(this, "Add key to binary blob for "+this+" but already finished"); return; } } if(logMINOR) Logger.minor(this, "Adding key "+block.getClientKey().getURI()+" to "+this, new Exception("debug")); try { binaryBlobWriter.addKey(block, context); } catch (IOException e) { Logger.error(this, "Failed to write key to binary blob stream: "+e, e); onFailure(new FetchException(FetchExceptionMode.BUCKET_ERROR, "Failed to write key to binary blob stream: "+e), null, context); } catch (BinaryBlobAlreadyClosedException e) { Logger.error(this, "Failed to write key to binary blob stream (already closed??): "+e, e); onFailure(new FetchException(FetchExceptionMode.BUCKET_ERROR, "Failed to write key to binary blob stream (already closed??): "+e), null, context); } }
cg = new ClientGetter(this, uri, ctx, RequestStarter.IMMEDIATE_SPLITFILE_PRIORITY_CLASS, null, new BinaryBlobWriter(new FileBucket(tempFile, false, false, false, false))); fetched = false;
context.uskManager.checkUSK(uri, persistent(), false); try { if (binaryBlobWriter != null && !dontFinalizeBlobWriter) binaryBlobWriter.finalizeBucket(); } catch (IOException ioe) { onFailure(new FetchException(FetchExceptionMode.BUCKET_ERROR, "Failed to close binary blob stream: "+ioe), null, context);
uri, tempContext, (short) 0, null, new BinaryBlobWriter(cleanedBlob), null);
if (binaryBlobWriter != null && !dontFinalizeBlobWriter) binaryBlobWriter.finalizeBucket(); } catch (IOException ioe) {
updateManager.getRevocationURI(), tempContext, (short) 0, null, new BinaryBlobWriter(cleanedBlob), null);
if (binaryBlobWriter != null && !dontFinalizeBlobWriter) binaryBlobWriter.finalizeBucket(); } catch (IOException ioe) { onFailure(new FetchException(FetchExceptionMode.BUCKET_ERROR, "Failed to close binary blob stream: "+ioe), null, context);
cg = new ClientGetter(this, uri, ctx, RequestStarter.IMMEDIATE_SPLITFILE_PRIORITY_CLASS, null, new BinaryBlobWriter(new FileBucket(tempBlobFile, false, false, false, false)), null); toStart = cg; } else {
manager.getRevocationURI(), ctxRevocation, aggressive ? RequestStarter.MAXIMUM_PRIORITY_CLASS : RequestStarter.IMMEDIATE_SPLITFILE_PRIORITY_CLASS, null, new BinaryBlobWriter(new ArrayBucket()), null); if(logMINOR) Logger.minor(this, "Queued another revocation fetcher (count="+revocationDNFCounter+")");
BinaryBlobWriter bbw = new BinaryBlobWriter(blobBucket); ClientGetter getter = new ClientGetter(fw, uri, ctx, (short) 0, null, bbw, false, null, null); getter.start(node.clientCore.clientContext);