1 31 package org.pdfbox.io; 32 33 import java.io.InputStream ; 34 import java.io.IOException ; 35 36 42 public class PushBackInputStream extends java.io.PushbackInputStream 43 { 44 45 53 public PushBackInputStream( InputStream input, int size ) throws IOException 54 { 55 super( input, size ); 56 if( input == null ) 57 { 58 throw new IOException ( "Error: input was null" ); 59 } 60 } 61 62 69 public int peek() throws IOException 70 { 71 int result = read(); 72 if( result != -1 ) 73 { 74 unread( result ); 75 } 76 return result; 77 } 78 79 86 public boolean isEOF() throws IOException 87 { 88 int peek = peek(); 89 return peek == -1; 90 } 91 92 100 public void fillBuffer() throws IOException 101 { 102 int bufferLength = buf.length; 103 byte[] tmpBuffer = new byte[bufferLength]; 104 int amountRead = 0; 105 int totalAmountRead = 0; 106 while( amountRead != -1 && totalAmountRead < bufferLength ) 107 { 108 amountRead = this.read( tmpBuffer, totalAmountRead, bufferLength - totalAmountRead ); 109 if( amountRead != -1 ) 110 { 111 totalAmountRead += amountRead; 112 } 113 } 114 this.unread( tmpBuffer, 0, totalAmountRead ); 115 } 116 } | Popular Tags |