use of java.util.zip.CheckedOutputStream in project hadoop by apache.
the class TestIndexCache method testBadIndex.
public void testBadIndex() throws Exception {
final int parts = 30;
fs.delete(p, true);
conf.setInt(TTConfig.TT_INDEX_CACHE, 1);
IndexCache cache = new IndexCache(conf);
Path f = new Path(p, "badindex");
FSDataOutputStream out = fs.create(f, false);
CheckedOutputStream iout = new CheckedOutputStream(out, new CRC32());
DataOutputStream dout = new DataOutputStream(iout);
for (int i = 0; i < parts; ++i) {
for (int j = 0; j < MapTask.MAP_OUTPUT_INDEX_RECORD_LENGTH / 8; ++j) {
if (0 == (i % 3)) {
dout.writeLong(i);
} else {
out.writeLong(i);
}
}
}
out.writeLong(iout.getChecksum().getValue());
dout.close();
try {
cache.getIndexInformation("badindex", 7, f, UserGroupInformation.getCurrentUser().getShortUserName());
fail("Did not detect bad checksum");
} catch (IOException e) {
if (!(e.getCause() instanceof ChecksumException)) {
throw e;
}
}
}
use of java.util.zip.CheckedOutputStream in project hadoop by apache.
the class TestShuffleHandler method createIndexFile.
private static void createIndexFile(File indexFile, Configuration conf) throws IOException {
if (indexFile.exists()) {
System.out.println("Deleting existing file");
indexFile.delete();
}
indexFile.createNewFile();
FSDataOutputStream output = FileSystem.getLocal(conf).getRaw().append(new Path(indexFile.getAbsolutePath()));
Checksum crc = new PureJavaCrc32();
crc.reset();
CheckedOutputStream chk = new CheckedOutputStream(output, crc);
String msg = "Writing new index file. This file will be used only " + "for the testing.";
chk.write(Arrays.copyOf(msg.getBytes(), MapTask.MAP_OUTPUT_INDEX_RECORD_LENGTH));
output.writeLong(chk.getChecksum().getValue());
output.close();
}
use of java.util.zip.CheckedOutputStream in project hadoop by apache.
the class SpillRecord method writeToFile.
public void writeToFile(Path loc, JobConf job, Checksum crc) throws IOException {
final FileSystem rfs = FileSystem.getLocal(job).getRaw();
CheckedOutputStream chk = null;
final FSDataOutputStream out = rfs.create(loc);
try {
if (crc != null) {
crc.reset();
chk = new CheckedOutputStream(out, crc);
chk.write(buf.array());
out.writeLong(chk.getChecksum().getValue());
} else {
out.write(buf.array());
}
} finally {
if (chk != null) {
chk.close();
} else {
out.close();
}
}
}
use of java.util.zip.CheckedOutputStream in project zookeeper by apache.
the class FileSnap method serialize.
/**
* serialize the datatree and session into the file snapshot
* @param dt the datatree to be serialized
* @param sessions the sessions to be serialized
* @param snapShot the file to store snapshot into
*/
public synchronized void serialize(DataTree dt, Map<Long, Integer> sessions, File snapShot) throws IOException {
if (!close) {
OutputStream sessOS = new BufferedOutputStream(new FileOutputStream(snapShot));
CheckedOutputStream crcOut = new CheckedOutputStream(sessOS, new Adler32());
//CheckedOutputStream cout = new CheckedOutputStream()
OutputArchive oa = BinaryOutputArchive.getArchive(crcOut);
FileHeader header = new FileHeader(SNAP_MAGIC, VERSION, dbId);
serialize(dt, sessions, oa, header);
long val = crcOut.getChecksum().getValue();
oa.writeLong(val, "val");
oa.writeString("/", "path");
sessOS.flush();
crcOut.close();
sessOS.close();
}
}
use of java.util.zip.CheckedOutputStream in project weave by continuuity.
the class ApplicationBundler method saveEntry.
/**
* Saves a class entry to the jar output.
*/
private void saveEntry(String entry, URL url, Set<String> entries, JarOutputStream jarOut, boolean compress) {
if (!entries.add(entry)) {
return;
}
try {
JarEntry jarEntry = new JarEntry(entry);
InputStream is = url.openStream();
try {
if (compress) {
jarOut.putNextEntry(jarEntry);
ByteStreams.copy(is, jarOut);
} else {
crc32.reset();
TransferByteOutputStream os = new TransferByteOutputStream();
CheckedOutputStream checkedOut = new CheckedOutputStream(os, crc32);
ByteStreams.copy(is, checkedOut);
checkedOut.close();
long size = os.size();
jarEntry.setMethod(JarEntry.STORED);
jarEntry.setSize(size);
jarEntry.setCrc(checkedOut.getChecksum().getValue());
jarOut.putNextEntry(jarEntry);
os.transfer(jarOut);
}
} finally {
is.close();
}
jarOut.closeEntry();
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
Aggregations