/** Append a CRC32 to a (short) byte[] */ private byte[] appendChecksum(byte[] data) { return checksumChecker.appendChecksum(data); }
private static byte[] encodeKey(int segNo, int blockNumber, ClientCHK key, boolean hasSplitfileKey, ChecksumChecker checker, SplitFileInserterStorage parent) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); try { dos.writeInt(segNo); dos.writeInt(blockNumber); dos.writeByte(1); // 1 = present, 0 = not present innerWriteKey(key, dos, hasSplitfileKey); dos.close(); } catch (IOException e) { throw new Error(e); // Impossible } byte[] fullBuf = baos.toByteArray(); byte[] bufNoKeyNumber = Arrays.copyOfRange(fullBuf, 8, fullBuf.length); byte[] ret = checker.appendChecksum(bufNoKeyNumber); return ret; }
/** Write details needed to restart the download from scratch, and to identify whether it is * useful to do so. */ private byte[] encodeAndChecksumOriginalDetails(FreenetURI thisKey, FreenetURI origKey, byte[] clientDetails, boolean isFinalFetch) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); dos.writeUTF(thisKey.toASCIIString()); dos.writeUTF(origKey.toASCIIString()); dos.writeBoolean(isFinalFetch); dos.writeInt(clientDetails.length); dos.write(clientDetails); dos.writeInt(maxRetries); dos.writeInt(cooldownTries); dos.writeLong(cooldownLength); return checksumChecker.appendChecksum(baos.toByteArray()); }