Example usage for org.apache.commons.codec.binary.yenc YEncHeader getLine

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

Introduction

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

Prototype

public int getLine() 

Source Link

Usage

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

public void encode(File input) throws EncoderException {
    try {/*from ww w  .  j  ava  2 s  . c om*/
        // 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");
    }

}