}
private ClientGet(DataInputStream dis, RequestIdentifier reqID, ClientContext context, ChecksumChecker checker)
throws IOException, StorageFormatException, ResumeFailedException {
super(dis, reqID, context);
ClientGetter getter = null;
long magic = dis.readLong();
if(magic != CLIENT_DETAIL_MAGIC)
throw new StorageFormatException("Bad magic for request");
int version = dis.readInt();
if(version != CLIENT_DETAIL_VERSION)
throw new StorageFormatException("Bad version "+version);
String s = dis.readUTF();
try {
uri = new FreenetURI(s);
} catch (MalformedURLException e) {
throw new StorageFormatException("Bad URI");
}
short r = dis.readShort();
try {
returnType = ReturnType.getByCode(r);
} catch (IllegalArgumentException e) {
throw new StorageFormatException("Bad return type "+r);
}
if(returnType == ReturnType.DISK) {
targetFile = new File(dis.readUTF());
} else {
targetFile = null;
}
binaryBlob = dis.readBoolean();
FetchContext fctx = null;
try {
DataInputStream innerDIS =
new DataInputStream(checker.checksumReaderWithLength(dis, context.tempBucketFactory, 65536));
try {
fctx = new FetchContext(innerDIS);
} catch (IOException e) {
Logger.error(this, "Unable to read fetch settings, will use default settings: "+e, e);
} finally {
innerDIS.close();
}
} catch (ChecksumFailedException e) {
Logger.error(this, "Unable to read fetch settings, will use default settings");
}
if(fctx == null) {
fctx = context.getDefaultPersistentFetchContext();
}
this.fctx = fctx;
fctx.eventProducer.addEventListener(this);
if(dis.readBoolean())
extensionCheck = dis.readUTF();
else
extensionCheck = null;
if(dis.readBoolean()) {
initialMetadata = BucketTools.restoreFrom(dis, context.persistentFG, context.persistentFileTracker, context.getPersistentMasterSecret());
// No way to recover if we don't have the initialMetadata.
} else {
initialMetadata = null;
}
if(finished) {
succeeded = dis.readBoolean();
readTransientProgressFields(dis);
if(succeeded) {
if(returnType == ReturnType.DIRECT) {
try {
DataInputStream innerDIS =
new DataInputStream(checker.checksumReaderWithLength(dis, context.tempBucketFactory, 65536));
try {
returnBucketDirect = BucketTools.restoreFrom(innerDIS, context.persistentFG, context.persistentFileTracker, context.getPersistentMasterSecret());
} catch (IOException e) {
Logger.error(this, "Failed to restore completed download-to-temp-space request, restarting instead");
returnBucketDirect = null;
succeeded = false;
finished = false;
} finally {
innerDIS.close();
}
} catch (ChecksumFailedException e) {
Logger.error(this, "Failed to restore completed download-to-temp-space request, restarting instead");
returnBucketDirect = null;
succeeded = false;
finished = false;
} catch (StorageFormatException e) {
Logger.error(this, "Failed to restore completed download-to-temp-space request, restarting instead");
returnBucketDirect = null;
succeeded = false;
finished = false;
}
}
} else {
try {
DataInputStream innerDIS =
new DataInputStream(checker.checksumReaderWithLength(dis, context.tempBucketFactory, 65536));
try {
getFailedMessage = new GetFailedMessage(innerDIS, reqID, foundDataLength, foundDataMimeType);
started = true;
} catch (IOException e) {
Logger.error(this, "Unable to restore reason for failure, restarting request : "+e, e);
finished = false;
getFailedMessage = null;
} finally {
innerDIS.close();
}
} catch (ChecksumFailedException e) {
Logger.error(this, "Unable to restore reason for failure, restarting request");
finished = false;
getFailedMessage = null;
}
}
} else {
getter = makeGetter(makeBucket(false));
try {
DataInputStream innerDIS =
new DataInputStream(checker.checksumReaderWithLength(dis, context.tempBucketFactory, 65536));
try {
if(getter.resumeFromTrivialProgress(innerDIS, context)) {
readTransientProgressFields(innerDIS);
}
} catch (IOException e) {
Logger.error(this, "Unable to restore splitfile, restarting: "+e);
} finally {