1 31 package org.pdfbox.pdfwriter; 32 33 34 35 import java.io.FilterOutputStream ; 36 import java.io.IOException ; 37 import java.io.OutputStream ; 38 39 46 public class COSStandardOutputStream extends FilterOutputStream 47 { 48 49 52 public static final byte[] CRLF = "\r\n".getBytes(); 53 54 57 public static final byte[] LF = "\n".getBytes(); 58 59 62 public static final byte[] EOL = System.getProperty("line.separator").getBytes(); 63 64 private long pos = 0; 66 private boolean onNewLine = false; 68 69 74 public COSStandardOutputStream(OutputStream out) 75 { 76 super(out); 77 } 78 83 public long getPos() 84 { 85 return pos; 86 } 87 92 public boolean isOnNewLine() 93 { 94 return onNewLine; 95 } 96 101 public void setOnNewLine(boolean newOnNewLine) 102 { 103 onNewLine = newOnNewLine; 104 } 105 106 115 public void write(byte[] b, int off, int len) throws IOException 116 { 117 setOnNewLine(false); 118 out.write(b, off, len); 119 pos += len; 120 } 121 122 129 public void write(int b) throws IOException 130 { 131 setOnNewLine(false); 132 out.write(b); 133 pos++; 134 } 135 136 141 public void writeCRLF() throws IOException 142 { 143 write(CRLF); 144 } 146 147 152 public void writeEOL() throws IOException 153 { 154 if (!isOnNewLine()) 155 { 156 write(EOL); 157 setOnNewLine(true); 158 } 159 } 160 161 166 public void writeLF() throws IOException 167 { 168 write(LF); 169 } 171 } | Popular Tags |