List of usage examples for org.apache.commons.codec.binary.yenc YEncHeader YEncHeader
public YEncHeader()
From source file:org.ambiance.codec.YEncEncoder.java
public void encode(File input) throws EncoderException { try {//from ww w .j a v a 2 s .co 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"); } }