Example usage for org.apache.commons.codec.binary.yenc YEncTrailer YEncTrailer

List of usage examples for org.apache.commons.codec.binary.yenc YEncTrailer YEncTrailer

Introduction

In this page you can find the example usage for org.apache.commons.codec.binary.yenc YEncTrailer YEncTrailer.

Prototype

public YEncTrailer() 

Source Link

Usage

From source file:org.ambiance.codec.YEncEncoder.java

public void encode(File input) throws EncoderException {
    try {/*from  w ww  .  ja  v a2s .c o m*/
        // Initialize
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(input));

        YEncHeader header = new YEncHeader();
        header.setName(input.getName());
        header.setLine(lineSize);

        YEncTrailer trailer = new YEncTrailer();

        CRC32 crc32 = new CRC32();

        StringBuffer outputName = new StringBuffer(outputDirName);
        outputName.append(File.separator);
        outputName.append(header.getName());
        outputName.append(extension);

        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(outputName.toString()));

        // Read and encode
        int c;
        long size = 0;
        while ((c = bis.read()) != -1) {
            crc32.update(c);
            if (size % header.getLine() == 0 && size != 0) {
                bos.write((int) '\r');
                bos.write((int) '\n');
            }
            size++;
        }
    } catch (FileNotFoundException e) {
        throw new EncoderException("Unable to find file to encode");
    } catch (IOException e) {
        throw new EncoderException("Unable to read file to encode");
    }

}