1 31 package org.pdfbox.filter; 32 33 import java.io.IOException ; 34 import java.io.InputStream ; 35 import java.io.OutputStream ; 36 37 import org.pdfbox.cos.COSDictionary; 38 39 61 public class RunLengthDecodeFilter implements Filter 62 { 63 private static final int RUN_LENGTH_EOD = 128; 64 65 68 public RunLengthDecodeFilter() 69 { 70 } 72 73 82 public void decode( InputStream compressedData, OutputStream result, COSDictionary options ) throws IOException 83 { 84 int dupAmount = -1; 85 byte[] buffer = new byte[128]; 86 while( (dupAmount = compressedData.read()) != -1 && dupAmount != RUN_LENGTH_EOD ) 87 { 88 if( dupAmount <= 127 ) 89 { 90 int amountToCopy = dupAmount+1; 91 int compressedRead = 0; 92 while( amountToCopy > 0 ) 93 { 94 compressedRead = compressedData.read( buffer, 0, amountToCopy ); 95 result.write( buffer, 0, compressedRead ); 96 amountToCopy -= compressedRead; 97 } 98 } 99 else 100 { 101 int dupByte = compressedData.read(); 102 for( int i=0; i<257-dupAmount; i++ ) 103 { 104 result.write( dupByte ); 105 } 106 } 107 } 108 } 109 110 119 public void encode( InputStream rawData, OutputStream result, COSDictionary options ) throws IOException 120 { 121 System.err.println( "Warning: RunLengthDecodeFilter.encode is not implemented yet, skipping this stream." ); 122 } 123 } | Popular Tags |