Skip to content

Commit

Permalink
Rename BaseParser to SeekableBaseParser
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximPlusov committed Oct 27, 2023
1 parent db3acbf commit 6d8382b
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -324,19 +324,19 @@ public int skip(int size) throws IOException {
return skipped;
}

public byte peek() throws IOException {
public int peek() throws IOException {
return peek(0);
}

public byte peek(int i) throws IOException {
public int peek(int i) throws IOException {
int index = pos + i;
if (index > buffer.length || index < 0) {
throw new IOException("Can't peek at index " + index + " in buffer in ASBufferingInputStream.");
}
if (eod != -1 && index >= eod) {
return -1;
}
return this.buffer[index];
return this.buffer[index] & 0xFF;
}

public void unread() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
*
* @author Sergey Shemyakov
*/
public class DecodedObjectStreamParser extends COSParser {
public class DecodedObjectStreamParser extends SeekableCOSParser {

private COSStream objectStream;
private Map<Integer, Long> internalOffsets;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/verapdf/parser/FunctionParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;

public class FunctionParser extends BaseParser {
public class FunctionParser extends SeekableBaseParser {

private static final Logger LOGGER = Logger.getLogger(FunctionParser.class.getCanonicalName());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ protected boolean isDigit() throws IOException {
return isDigit(this.source.peek());
}

protected static boolean isDigit(byte c) {
protected static boolean isDigit(int c) {
return c >= ASCII_ZERO && c <= ASCII_NINE;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/verapdf/parser/PDFParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
/**
* @author Timur Kamalov
*/
public class PDFParser extends COSParser {
public class PDFParser extends SeekableCOSParser {

private static final Logger LOGGER = Logger.getLogger(PDFParser.class.getCanonicalName());

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/verapdf/parser/PDFStreamParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ public Object parseNextToken() throws IOException {
Object result = null;

skipSpaces(true);
byte nextByte = source.peek();
int nextByte = source.peek();
if (nextByte == -1) {
return null;
}

byte c = nextByte;
int c = nextByte;

switch (c) {
case '(':
Expand Down Expand Up @@ -270,7 +270,7 @@ protected String nextOperator() throws IOException {

//maximum possible length of an operator is 3 and we'll leave some space for invalid cases
StringBuilder buffer = new StringBuilder(5);
byte nextByte = source.peek();
int nextByte = source.peek();
while (!source.isEOF() &&
!CharTable.isSpace(nextByte) && nextByte != ']' &&
nextByte != '[' && nextByte != '<' &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,31 @@
/**
* @author Timur Kamalov
*/
public class BaseParser {
public class SeekableBaseParser {

private static final Logger LOGGER = Logger.getLogger(BaseParser.class.getCanonicalName());
private static final Logger LOGGER = Logger.getLogger(SeekableBaseParser.class.getCanonicalName());

private static final byte ASCII_ZERO = 48;
private static final byte ASCII_NINE = 57;

protected SeekableInputStream source;
private Token token;

public BaseParser(SeekableInputStream stream) throws IOException {
public SeekableBaseParser(SeekableInputStream stream) throws IOException {
if (stream == null) {
throw new IOException("Can't create SeekableStream, passed seekableStream is null");
}
this.source = stream;
}

public BaseParser(String fileName) throws IOException {
public SeekableBaseParser(String fileName) throws IOException {
if (fileName == null) {
throw new FileNotFoundException("Can't create SeekableStream from file, filename is null");
}
this.source = new InternalInputStream(fileName);
}

public BaseParser(InputStream fileStream) throws IOException {
public SeekableBaseParser(InputStream fileStream) throws IOException {
if (fileStream == null) {
throw new IOException("Can't create SeekableStream, fileStream is null");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
/**
* @author Timur Kamalov
*/
public class COSParser extends BaseParser {
public class SeekableCOSParser extends SeekableBaseParser {

private static final Logger LOGGER = Logger.getLogger(COSParser.class.getCanonicalName());
private static final Logger LOGGER = Logger.getLogger(SeekableCOSParser.class.getCanonicalName());

/**
* Linearization dictionary must be in first 1024 bytes of document
Expand All @@ -57,24 +57,24 @@ public class COSParser extends BaseParser {

protected boolean flag = true;

public COSParser(final SeekableInputStream seekableInputStream) throws IOException {
public SeekableCOSParser(final SeekableInputStream seekableInputStream) throws IOException {
super(seekableInputStream);
}

public COSParser(final String filename) throws IOException {
public SeekableCOSParser(final String filename) throws IOException {
super(filename);
}

public COSParser(final InputStream fileStream) throws IOException {
public SeekableCOSParser(final InputStream fileStream) throws IOException {
super(fileStream);
}

public COSParser(final COSDocument document, final String filename) throws IOException { //tmp ??
public SeekableCOSParser(final COSDocument document, final String filename) throws IOException { //tmp ??
this(filename);
this.document = document;
}

public COSParser(final COSDocument document, final InputStream fileStream) throws IOException { //tmp ??
public SeekableCOSParser(final COSDocument document, final InputStream fileStream) throws IOException { //tmp ??
this(fileStream);
this.document = document;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/verapdf/parser/SignatureParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
*
* @author Sergey Shemyakov
*/
public class SignatureParser extends COSParser {
public class SignatureParser extends SeekableCOSParser {


private static final Logger LOGGER = Logger.getLogger(SignatureParser.class.getCanonicalName());
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/verapdf/pd/font/cff/CFFFontBaseParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public CFFFontBaseParser(SeekableInputStream source) {

protected void readTopDictUnit() throws IOException {
try {
int next = this.source.peek() & 0xFF;
int next = this.source.peek();
if ((next > 27 && next < 31) || (next > 31 && next < 255)) {
this.stack.add(readNumber());
} else {
Expand Down Expand Up @@ -152,7 +152,7 @@ protected void readCharStrings() throws IOException {
}

protected void readPrivateDictUnit() throws IOException {
int next = this.source.peek() & 0xFF;
int next = this.source.peek();
if ((next > 27 && next < 31) || (next > 31 && next < 255)) {
this.stack.add(readNumber());
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/verapdf/pd/font/stdmetrics/AFMParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
package org.verapdf.pd.font.stdmetrics;

import org.verapdf.as.io.ASInputStream;
import org.verapdf.parser.BaseParser;
import org.verapdf.parser.SeekableBaseParser;
import org.verapdf.parser.Token;

import java.io.IOException;
Expand All @@ -31,7 +31,7 @@
*
* @author Sergey Shemyakov
*/
public class AFMParser extends BaseParser {
public class AFMParser extends SeekableBaseParser {

private static final String START_CHAR_METRICS_STRING = "StartCharMetrics";
private static final String FONT_NAME_STRING = "FontName";
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/verapdf/pd/font/type1/PDType1Font.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.verapdf.as.io.ASInputStream;
import org.verapdf.as.io.ASMemoryInStream;
import org.verapdf.cos.*;
import org.verapdf.parser.COSParser;
import org.verapdf.parser.SeekableCOSParser;
import org.verapdf.pd.font.Encoding;
import org.verapdf.pd.font.FontProgram;
import org.verapdf.pd.font.PDFontDescriptor;
Expand Down Expand Up @@ -97,7 +97,7 @@ public Set<String> getDescriptorCharSet() {
ASMemoryInStream stream =
new ASMemoryInStream(descriptorCharSetString.getBytes(StandardCharsets.ISO_8859_1));
Set<String> descriptorCharSet = new TreeSet<>();
COSParser parser = new COSParser(stream);
SeekableCOSParser parser = new SeekableCOSParser(stream);
COSObject glyphName = parser.nextObject();
while (!glyphName.empty()) {
if (glyphName.getType() == COSObjType.COS_NAME) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.verapdf.as.io.ASInputStream;
import org.verapdf.as.io.ASMemoryInStream;
import org.verapdf.cos.COSKey;
import org.verapdf.parser.BaseParser;
import org.verapdf.parser.SeekableBaseParser;
import org.verapdf.parser.Token;
import org.verapdf.pd.font.CFFNumber;

Expand All @@ -42,7 +42,7 @@
*
* @author Sergey Shemyakov
*/
class Type1PrivateParser extends BaseParser {
class Type1PrivateParser extends SeekableBaseParser {

private static final Logger LOGGER = Logger.getLogger(Type1PrivateParser.class.getCanonicalName());

Expand Down

0 comments on commit 6d8382b

Please sign in to comment.