188189190191192193194195196197198
} // compute data CRC DataChecksum checksum = DataChecksum.newDataChecksum( DataChecksum.CHECKSUM_CRC32, 1); checksum.update(data, 0, data.length); // compute checksum final int crc = fs.getFileCrc(foo); System.out.println("crc=" + crc);
185186187188189190191192193194195
} // compute data CRC DataChecksum checksum = DataChecksum.newDataChecksum( DataChecksum.CHECKSUM_CRC32, 1); checksum.update(data, 0, data.length); //compute checksum final int crc = hdfs.getFileCrc(foo); System.out.println("crc=" + crc);
385386387388389390391392393394395
while (true) { int bytesRead = streamIn.read(buf); if (bytesRead == -1) { break; } else checksum.update(buf, 0, bytesRead); } return (int) checksum.getValue(); } finally { IOUtils.closeStream(streamIn); }
434435436437438439440441442443444
} finally { ra.close(); } // compute checksum dcs.update(b, 0, lastchunksize); dcs.writeValue(b, 0, false); // update metaFile RandomAccessFile metaRAF = new RandomAccessFile(metafile, "rw"); try {
457458459460461462463464465466467
// read last chunk ra.seek(lastchunkoffset); ra.readFully(b, 0, lastchunksize); // compute checksum dcs.update(b, 0, lastchunksize); dcs.writeValue(b, 0, false); ra.seek(newBlockFileSize - checksumSize); ra.write(b, 0, checksumSize); }