Search in sources :

Example 1 with CheckedOutputStream

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;
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) CRC32(java.util.zip.CRC32) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) DataOutputStream(java.io.DataOutputStream) ChecksumException(org.apache.hadoop.fs.ChecksumException) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) CheckedOutputStream(java.util.zip.CheckedOutputStream) IOException(java.io.IOException)

Example 2 with CheckedOutputStream

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();
}
Also used : Path(org.apache.hadoop.fs.Path) PureJavaCrc32(org.apache.hadoop.util.PureJavaCrc32) Checksum(java.util.zip.Checksum) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) CheckedOutputStream(java.util.zip.CheckedOutputStream)

Example 3 with CheckedOutputStream

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();
        }
    }
}
Also used : FileSystem(org.apache.hadoop.fs.FileSystem) CheckedOutputStream(java.util.zip.CheckedOutputStream) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream)

Example 4 with CheckedOutputStream

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();
    }
}
Also used : BinaryOutputArchive(org.apache.jute.BinaryOutputArchive) OutputArchive(org.apache.jute.OutputArchive) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) CheckedOutputStream(java.util.zip.CheckedOutputStream) FileOutputStream(java.io.FileOutputStream) CheckedOutputStream(java.util.zip.CheckedOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) Adler32(java.util.zip.Adler32)

Example 5 with CheckedOutputStream

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);
    }
}
Also used : InputStream(java.io.InputStream) CheckedOutputStream(java.util.zip.CheckedOutputStream) JarEntry(java.util.jar.JarEntry) IOException(java.io.IOException)

Aggregations

CheckedOutputStream (java.util.zip.CheckedOutputStream)10 IOException (java.io.IOException)4 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)4 DataOutputStream (java.io.DataOutputStream)3 OutputStream (java.io.OutputStream)3 Adler32 (java.util.zip.Adler32)3 CRC32 (java.util.zip.CRC32)3 BufferedOutputStream (java.io.BufferedOutputStream)2 FileOutputStream (java.io.FileOutputStream)2 Path (org.apache.hadoop.fs.Path)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 PrintStream (java.io.PrintStream)1 JarEntry (java.util.jar.JarEntry)1 Checksum (java.util.zip.Checksum)1 ChecksumException (org.apache.hadoop.fs.ChecksumException)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 PureJavaCrc32 (org.apache.hadoop.util.PureJavaCrc32)1 BinaryOutputArchive (org.apache.jute.BinaryOutputArchive)1 OutputArchive (org.apache.jute.OutputArchive)1