From a1661bf79a15a25c667136dcffd8ef86c80bba7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ha=CC=8Avard=20Ottestad?= Date: Sun, 9 Jul 2023 17:33:24 +0200 Subject: [PATCH 1/2] GH-4665 Clean up HDT code --- .../java/org/eclipse/rdf4j/rio/hdt/CRC32.java | 2 +- .../org/eclipse/rdf4j/rio/hdt/HDTArray.java | 18 ++++---- .../rdf4j/rio/hdt/HDTArrayFactory.java | 2 +- .../eclipse/rdf4j/rio/hdt/HDTArrayLog64.java | 10 ++--- .../org/eclipse/rdf4j/rio/hdt/HDTBitmap.java | 2 +- .../eclipse/rdf4j/rio/hdt/HDTDictionary.java | 8 ++-- .../rdf4j/rio/hdt/HDTDictionarySection.java | 10 ++--- .../rio/hdt/HDTDictionarySectionFactory.java | 2 +- .../rio/hdt/HDTDictionarySectionPFC.java | 10 ++--- .../org/eclipse/rdf4j/rio/hdt/HDTGlobal.java | 8 ++-- .../org/eclipse/rdf4j/rio/hdt/HDTHeader.java | 10 ++--- .../org/eclipse/rdf4j/rio/hdt/HDTParser.java | 11 ++--- .../org/eclipse/rdf4j/rio/hdt/HDTPart.java | 44 +++++++++---------- .../org/eclipse/rdf4j/rio/hdt/HDTTriples.java | 16 +++---- .../rdf4j/rio/hdt/HDTTriplesSection.java | 2 +- .../rio/hdt/HDTTriplesSectionBitmap.java | 4 +- .../rio/hdt/HDTTriplesSectionFactory.java | 4 +- .../java/org/eclipse/rdf4j/rio/hdt/VByte.java | 7 ++- .../org/eclipse/rdf4j/rio/hdt/VByteTest.java | 2 +- 19 files changed, 85 insertions(+), 87 deletions(-) diff --git a/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/CRC32.java b/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/CRC32.java index 4223303386b..206edcc16f6 100644 --- a/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/CRC32.java +++ b/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/CRC32.java @@ -82,6 +82,6 @@ public long getValue() { @Override public void reset() { - value = 0xFFFFFFFF; + value = 0; } } diff --git a/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTArray.java b/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTArray.java index 0e9908d225c..42c84866f50 100644 --- a/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTArray.java +++ b/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTArray.java @@ -35,7 +35,7 @@ * @author Bart Hanssens */ abstract class HDTArray extends HDTPart { - protected enum Type { + enum Type { LOG64(1), UINT32(2), UINT64(3); @@ -47,7 +47,7 @@ protected enum Type { * * @return value 1,2 or 3 */ - public int getValue() { + int getValue() { return value; } @@ -56,22 +56,22 @@ public int getValue() { } } - protected int nrbits; - protected int entries; + int nrbits; + int entries; /** * Get the type of the array * * @return byte */ - protected abstract int getType(); + abstract int getType(); /** * Get number of bits used to encode an entry * * @return positive integer value */ - protected int getNrBits() { + int getNrBits() { return nrbits; } @@ -80,7 +80,7 @@ protected int getNrBits() { * * @return positive integer value */ - protected int size() { + int size() { return entries; } @@ -90,10 +90,10 @@ protected int size() { * @param i zero-based index * @return entry */ - protected abstract int get(int i); + abstract int get(int i); @Override - protected void parse(InputStream is) throws IOException { + void parse(InputStream is) throws IOException { CRC8 crc8 = new CRC8(); crc8.update(getType()); diff --git a/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTArrayFactory.java b/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTArrayFactory.java index 5f1b24177f9..3e222c617e5 100644 --- a/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTArrayFactory.java +++ b/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTArrayFactory.java @@ -20,7 +20,7 @@ */ class HDTArrayFactory { - protected static HDTArray parse(InputStream is) throws IOException { + static HDTArray parse(InputStream is) throws IOException { int dtype = is.read(); if (dtype != HDTArray.Type.LOG64.getValue()) { throw new UnsupportedOperationException("Array section: encoding " + Long.toHexString(dtype) + diff --git a/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTArrayLog64.java b/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTArrayLog64.java index b6ef0c9e582..d3c084271b1 100644 --- a/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTArrayLog64.java +++ b/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTArrayLog64.java @@ -34,15 +34,15 @@ * @author Bart Hanssens */ class HDTArrayLog64 extends HDTArray { - private byte buffer[]; + private byte[] buffer; @Override - protected int getType() { + int getType() { return HDTArray.Type.LOG64.getValue(); } @Override - protected int get(int i) { + int get(int i) { // start byte of the value, and start bit in that start byte int bytePos = (i * nrbits) / 8; int bitPos = (i * nrbits) % 8; @@ -63,14 +63,14 @@ protected int get(int i) { } @Override - protected void parse(InputStream is) throws IOException { + void parse(InputStream is) throws IOException { super.parse(is); // don't close CheckedInputStream, as it will close the underlying inputstream try (UncloseableInputStream uis = new UncloseableInputStream(is); CheckedInputStream cis = new CheckedInputStream(uis, new CRC32())) { // read bytes, minimum 1 - long bytes = (nrbits * entries + 7) / 8; + long bytes = ((long) nrbits * entries + 7) / 8; if (bytes > Integer.MAX_VALUE) { throw new UnsupportedOperationException("Maximum number of bytes in array exceeded: " + bytes); } diff --git a/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTBitmap.java b/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTBitmap.java index ac60ac9e8c7..30bfc002709 100644 --- a/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTBitmap.java +++ b/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTBitmap.java @@ -62,7 +62,7 @@ protected void parse(InputStream is) throws IOException { ", but only bitmap v1 is supported"); } - long b = (int) VByte.decode(cis); + long b = VByte.decode(cis); if (b > Integer.MAX_VALUE) { throw new UnsupportedOperationException("Maximum number of entries in bitmap exceeded: " + b); } diff --git a/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTDictionary.java b/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTDictionary.java index 8e904c3fccc..4a2bff3b557 100644 --- a/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTDictionary.java +++ b/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTDictionary.java @@ -36,13 +36,13 @@ * @author Bart Hanssens */ class HDTDictionary extends HDTPart { - protected final static byte[] DICT_FORMAT = "" + final static byte[] DICT_FORMAT = "" .getBytes(StandardCharsets.US_ASCII); - protected final static String DICT_MAPPING = "mapping"; - protected final static String DICT_ELEMENTS = "elements"; + final static String DICT_MAPPING = "mapping"; + final static String DICT_ELEMENTS = "elements"; @Override - protected void parse(InputStream is) throws IOException { + void parse(InputStream is) throws IOException { // don't close CheckedInputStream, as it will close the underlying inputstream try (UncloseableInputStream uis = new UncloseableInputStream(is); CheckedInputStream cis = new CheckedInputStream(uis, new CRC16())) { diff --git a/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTDictionarySection.java b/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTDictionarySection.java index aef6e771a5d..cca1f79b9b4 100644 --- a/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTDictionarySection.java +++ b/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTDictionarySection.java @@ -18,7 +18,7 @@ * @author Bart Hanssens */ abstract class HDTDictionarySection extends HDTPart { - protected enum Type { + enum Type { PLAIN(1), FRONT(2), HTFC(3), @@ -28,7 +28,7 @@ protected enum Type { private final int value; - protected int getValue() { + int getValue() { return value; } @@ -42,7 +42,7 @@ protected int getValue() { * * @return */ - protected abstract int size(); + abstract int size(); /** * Get the entry @@ -50,7 +50,7 @@ protected int getValue() { * @param i zero-based index * @return */ - protected abstract byte[] get(int i) throws IOException; + abstract byte[] get(int i) throws IOException; /** * Constructor @@ -58,7 +58,7 @@ protected int getValue() { * @param pos position * @param name name */ - protected HDTDictionarySection(String name, long pos) { + HDTDictionarySection(String name, long pos) { super(name, pos); } } diff --git a/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTDictionarySectionFactory.java b/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTDictionarySectionFactory.java index dd3387f80b2..293a664a1a4 100644 --- a/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTDictionarySectionFactory.java +++ b/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTDictionarySectionFactory.java @@ -28,7 +28,7 @@ class HDTDictionarySectionFactory { * @return dictionary section * @throws IOException */ - protected static HDTDictionarySection parse(InputStream is, String name, long pos) throws IOException { + static HDTDictionarySection parse(InputStream is, String name, long pos) throws IOException { int dtype = is.read(); if (dtype != HDTDictionarySection.Type.FRONT.getValue()) { throw new UnsupportedOperationException("Dictionary " + name + ": encoding " diff --git a/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTDictionarySectionPFC.java b/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTDictionarySectionPFC.java index 50add6ab32a..625238881b9 100644 --- a/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTDictionarySectionPFC.java +++ b/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTDictionarySectionPFC.java @@ -74,17 +74,17 @@ protected boolean removeEldestEntry(Map.Entry eldest) { * @param name * @param pos */ - protected HDTDictionarySectionPFC(String name, long pos) { + HDTDictionarySectionPFC(String name, long pos) { super(name, pos); } @Override - protected int size() { + int size() { return totalStrings; } @Override - protected byte[] get(int i) throws IOException { + byte[] get(int i) throws IOException { // HDT index start counting from 1 int idx = i - 1; @@ -101,7 +101,7 @@ protected byte[] get(int i) throws IOException { } @Override - protected void parse(InputStream is) throws IOException { + void parse(InputStream is) throws IOException { CRC8 crc8 = new CRC8(); crc8.update((byte) HDTDictionarySection.Type.FRONT.getValue()); @@ -112,7 +112,7 @@ protected void parse(InputStream is) throws IOException { CheckedInputStream cis = new CheckedInputStream(uis, crc8)) { long val = VByte.decode(cis); - if (totalStrings > Integer.MAX_VALUE) { + if (val > Integer.MAX_VALUE) { throw new UnsupportedOperationException(getDebugPartStr() + " max number of strings exceeded: " + val); } totalStrings = (int) val; diff --git a/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTGlobal.java b/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTGlobal.java index 1fe16ca97e7..e9fad13c036 100644 --- a/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTGlobal.java +++ b/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTGlobal.java @@ -38,12 +38,12 @@ * @author Bart Hanssens */ class HDTGlobal extends HDTPart { - protected final static byte[] GLOBAL_FORMAT = "".getBytes(StandardCharsets.US_ASCII); - protected final static String GLOBAL_BASEURI = "BaseUri"; - protected final static String GLOBAL_SOFTWARE = "Software"; + final static byte[] GLOBAL_FORMAT = "".getBytes(StandardCharsets.US_ASCII); + final static String GLOBAL_BASEURI = "BaseUri"; + final static String GLOBAL_SOFTWARE = "Software"; @Override - protected void parse(InputStream is) throws IOException { + void parse(InputStream is) throws IOException { // don't close CheckedInputStream, as it will close the underlying inputstream try (UncloseableInputStream uis = new UncloseableInputStream(is); CheckedInputStream cis = new CheckedInputStream(uis, new CRC16())) { diff --git a/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTHeader.java b/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTHeader.java index 00fc2221542..0c098087399 100644 --- a/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTHeader.java +++ b/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTHeader.java @@ -37,13 +37,13 @@ */ class HDTHeader extends HDTPart { - protected final static byte[] HEADER_FORMAT = "ntriples".getBytes(StandardCharsets.US_ASCII); - protected final static String HEADER_LENGTH = "length"; + final static byte[] HEADER_FORMAT = "ntriples".getBytes(StandardCharsets.US_ASCII); + final static String HEADER_LENGTH = "length"; private byte[] headerData; @Override - protected void parse(InputStream is) throws IOException { + void parse(InputStream is) throws IOException { // don't close CheckedInputStream, as it will close the underlying inputstream try (UncloseableInputStream uis = new UncloseableInputStream(is); CheckedInputStream cis = new CheckedInputStream(uis, new CRC16())) { @@ -63,7 +63,7 @@ protected void parse(InputStream is) throws IOException { * * @return byte array */ - protected byte[] getHeaderData() { + byte[] getHeaderData() { return headerData; } @@ -75,7 +75,7 @@ protected byte[] getHeaderData() { * @throws IOException */ private byte[] parseHeaderData(InputStream is, int len) throws IOException { - byte b[] = new byte[len]; + byte[] b = new byte[len]; is.read(b); return b; } diff --git a/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTParser.java b/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTParser.java index eeaceb6858f..532f7bd33d9 100644 --- a/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTParser.java +++ b/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTParser.java @@ -97,9 +97,9 @@ public synchronized void parse(InputStream in, String baseURI) throw new IllegalArgumentException("Input stream must not be 'null'"); } - if (in instanceof FileInputStream) { - // "TODO: use more optimized way to parse the file, eg. filechannel / membuffer" - } +// if (in instanceof FileInputStream) { +// TODO: use more optimized way to parse the file, eg. filechannel / membuffer +// } HDTDictionarySection shared = null; HDTDictionarySection subjects = null; @@ -163,9 +163,10 @@ public synchronized void parse(InputStream in, String baseURI) rdfHandler.startRDF(); } - int cnt = 0; + assert shared != null; int size = shared.size(); + assert section != null; while (section.hasNext()) { int[] t = section.next(); byte[] s = getSO(t[0], size, shared, subjects); @@ -188,7 +189,7 @@ public synchronized void parse(InputStream in, String baseURI) */ @Override public synchronized void parse(Reader reader, String baseURI) - throws IOException, RDFParseException, RDFHandlerException { + throws RDFParseException, RDFHandlerException { throw new UnsupportedOperationException("HDT is binary, text readers not supported."); } diff --git a/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTPart.java b/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTPart.java index c9d9f8c1f54..dc6b3e3a850 100644 --- a/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTPart.java +++ b/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTPart.java @@ -34,7 +34,7 @@ * @author Bart Hanssens */ abstract class HDTPart { - protected enum Type { + enum Type { GLOBAL((byte) 1), HEADER((byte) 2), DICTIONARY((byte) 3), @@ -47,7 +47,7 @@ protected enum Type { * * @return value 1,2 or 3 */ - protected byte getValue() { + byte getValue() { return value; } @@ -56,14 +56,14 @@ protected byte getValue() { } } - protected final static byte[] COOKIE = "$HDT".getBytes(StandardCharsets.US_ASCII); + final static byte[] COOKIE = "$HDT".getBytes(StandardCharsets.US_ASCII); // TODO: make configurable, buffer for reading object values private final static int BUFLEN = 1 * 1024 * 1024; // for debugging purposes - protected final String name; - protected final long pos; - protected Map properties; + final String name; + final long pos; + Map properties; /** * Parse from input stream @@ -71,14 +71,14 @@ protected byte getValue() { * @param is * @throws IOException */ - protected abstract void parse(InputStream is) throws IOException; + abstract void parse(InputStream is) throws IOException; /** * Get properties, if any. * * @return key, value map */ - protected Map getProperties() { + Map getProperties() { return properties; } @@ -88,7 +88,7 @@ protected Map getProperties() { * @param name part name * @param pos starting position in input stream */ - protected HDTPart(String name, long pos) { + HDTPart(String name, long pos) { this.name = name; this.pos = pos; } @@ -96,7 +96,7 @@ protected HDTPart(String name, long pos) { /** * Constructor */ - protected HDTPart() { + HDTPart() { this("", -1); } @@ -105,7 +105,7 @@ protected HDTPart() { * * @return string */ - protected String getDebugPartStr() { + String getDebugPartStr() { if (name == null || name.isEmpty()) { return ""; } @@ -119,7 +119,7 @@ protected String getDebugPartStr() { * @param ctype control type * @throws IOException */ - protected static void checkControl(InputStream is, HDTPart.Type ctype) throws IOException { + static void checkControl(InputStream is, HDTPart.Type ctype) throws IOException { byte[] cookie = new byte[COOKIE.length]; is.read(cookie); if (!Arrays.equals(cookie, COOKIE)) { @@ -139,7 +139,7 @@ protected static void checkControl(InputStream is, HDTPart.Type ctype) throws IO * @param format * @throws IOException */ - protected static void checkFormat(InputStream is, byte[] format) throws IOException { + static void checkFormat(InputStream is, byte[] format) throws IOException { byte[] b = new byte[format.length]; is.read(b); if (!Arrays.equals(b, format)) { @@ -155,7 +155,7 @@ protected static void checkFormat(InputStream is, byte[] format) throws IOExcept * @return * @throws IOException */ - protected static byte[] readToNull(InputStream is) throws IOException { + static byte[] readToNull(InputStream is) throws IOException { byte[] buf = new byte[BUFLEN]; int len = 0; @@ -176,7 +176,7 @@ protected static byte[] readToNull(InputStream is) throws IOException { * @param start position to start from * @return position of first NULL byte */ - protected static int countToNull(byte[] b, int start) throws IOException { + static int countToNull(byte[] b, int start) throws IOException { for (int i = start; i < b.length; i++) { if (b[i] == 0b00) { return i; @@ -193,7 +193,7 @@ protected static int countToNull(byte[] b, int start) throws IOException { * @return key, value map * @throws IOException */ - protected static Map getProperties(InputStream is) throws IOException { + static Map getProperties(InputStream is) throws IOException { return mapProperties(readToNull(is)); } @@ -203,15 +203,15 @@ protected static Map getProperties(InputStream is) throws IOExce * @param props * @return */ - protected static Map mapProperties(byte[] props) { + static Map mapProperties(byte[] props) { Map map = new HashMap<>(); if (props == null || props.length == 0) { return map; } - String strs[] = new String(props, 0, props.length, StandardCharsets.US_ASCII).split(";"); - for (String str : strs) { - String prop[] = str.split("="); + String[] strings = new String(props, StandardCharsets.US_ASCII).split(";"); + for (String string : strings) { + String[] prop = string.split("="); if (prop.length == 2) { map.put(prop[0], prop[1]); } @@ -229,7 +229,7 @@ protected static Map mapProperties(byte[] props) { * @return positive integer * @throws IOException */ - protected int getIntegerProperty(Map props, String prop, String name) throws IOException { + int getIntegerProperty(Map props, String prop, String name) throws IOException { int len; String str = props.getOrDefault(prop, "0"); @@ -252,7 +252,7 @@ protected int getIntegerProperty(Map props, String prop, String * @param len number of bytes of the checksum * @throws IOException */ - protected static void checkCRC(CheckedInputStream cis, InputStream is, int len) throws IOException { + static void checkCRC(CheckedInputStream cis, InputStream is, int len) throws IOException { long calc = cis.getChecksum().getValue(); byte[] checksum = new byte[len]; diff --git a/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTTriples.java b/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTTriples.java index ec166aa7593..f18302bf008 100644 --- a/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTTriples.java +++ b/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTTriples.java @@ -38,7 +38,7 @@ * @author Bart Hanssens */ class HDTTriples extends HDTPart { - protected enum Order { + enum Order { UNKNOWN(0), SPO(1), SOP(2), @@ -49,7 +49,7 @@ protected enum Order { private final int value; - protected int getValue() { + int getValue() { return value; } @@ -63,12 +63,12 @@ protected int getValue() { } } - protected final static byte[] FORMAT_LIST = "" + final static byte[] FORMAT_LIST = "" .getBytes(StandardCharsets.US_ASCII); - protected final static byte[] FORMAT_BITMAP = "" + final static byte[] FORMAT_BITMAP = "" .getBytes(StandardCharsets.US_ASCII); - protected final static String ORDER = "order"; - protected final static String NUM = "numTriples"; + final static String ORDER = "order"; + final static String NUM = "numTriples"; private Order order; private int nrtriples; @@ -78,12 +78,12 @@ protected int getValue() { * * @return enum */ - protected Order getOrder() { + Order getOrder() { return order; } @Override - protected void parse(InputStream is) throws IOException { + void parse(InputStream is) throws IOException { // don't close CheckedInputStream, as it will close the underlying inputstream try (UncloseableInputStream uis = new UncloseableInputStream(is); CheckedInputStream cis = new CheckedInputStream(uis, new CRC16())) { diff --git a/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTTriplesSection.java b/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTTriplesSection.java index d3d66a9fc33..baf6055e387 100644 --- a/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTTriplesSection.java +++ b/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTTriplesSection.java @@ -27,5 +27,5 @@ abstract class HDTTriplesSection extends HDTPart implements Iterator { * @param order * @throws IOException */ - protected abstract void parse(InputStream is, HDTTriples.Order order) throws IOException; + abstract void parse(InputStream is, HDTTriples.Order order) throws IOException; } diff --git a/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTTriplesSectionBitmap.java b/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTTriplesSectionBitmap.java index 3e94463187c..fe9fd93866d 100644 --- a/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTTriplesSectionBitmap.java +++ b/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTTriplesSectionBitmap.java @@ -79,12 +79,12 @@ public int[] next() { } @Override - protected void parse(InputStream is) throws IOException { + void parse(InputStream is) throws IOException { parse(is, HDTTriples.Order.SPO); } @Override - protected void parse(InputStream is, HDTTriples.Order order) throws IOException { + void parse(InputStream is, HDTTriples.Order order) throws IOException { bitmapY = new HDTBitmap(); bitmapY.parse(is); sizeY = bitmapY.size(); diff --git a/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTTriplesSectionFactory.java b/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTTriplesSectionFactory.java index b35f237dbf7..0d1b357d5d7 100644 --- a/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTTriplesSectionFactory.java +++ b/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTTriplesSectionFactory.java @@ -10,8 +10,6 @@ *******************************************************************************/ package org.eclipse.rdf4j.rio.hdt; -import java.io.IOException; - /** * HDT Array factory. * @@ -19,7 +17,7 @@ */ class HDTTriplesSectionFactory { - protected static HDTTriplesSection parse(String str) throws IOException { + static HDTTriplesSection parse(String str) { if (!str.equals(new String(HDTTriples.FORMAT_BITMAP))) { throw new UnsupportedOperationException( "Triples section: " + str + ", but only bitmap encoding is supported"); diff --git a/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/VByte.java b/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/VByte.java index 0afa56534ff..1879c23aa3a 100644 --- a/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/VByte.java +++ b/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/VByte.java @@ -72,7 +72,7 @@ public static long decode(InputStream is) throws IOException { int i = 0; do { buffer[i] = (byte) is.read(); - } while (i < buffer.length && hasNext(buffer[i++])); + } while (i + 1 < buffer.length && hasNext(buffer[i++])); return decode(buffer, i); } @@ -82,15 +82,14 @@ public static long decode(InputStream is) throws IOException { * @param b byte array * @param start starting position * @return decode value - * @throws IOException */ - public static long decodeFrom(byte[] b, int start) throws IOException { + public static long decodeFrom(byte[] b, int start) { byte[] buffer = new byte[8]; int i = 0; do { buffer[i] = b[start + i]; - } while (i < buffer.length && hasNext(buffer[i++])); + } while (i + 1 < buffer.length && hasNext(buffer[i++])); return decode(buffer, i); } diff --git a/core/rio/hdt/src/test/java/org/eclipse/rdf4j/rio/hdt/VByteTest.java b/core/rio/hdt/src/test/java/org/eclipse/rdf4j/rio/hdt/VByteTest.java index 8f70e8da175..b57f691cd84 100644 --- a/core/rio/hdt/src/test/java/org/eclipse/rdf4j/rio/hdt/VByteTest.java +++ b/core/rio/hdt/src/test/java/org/eclipse/rdf4j/rio/hdt/VByteTest.java @@ -34,7 +34,7 @@ public void test128() { @Test public void test128Input() { - byte b[] = new byte[] { (byte) 0x00, (byte) 0x81 }; + byte[] b = new byte[] { (byte) 0x00, (byte) 0x81 }; try (ByteArrayInputStream bis = new ByteArrayInputStream(b)) { assertEquals(128, VByte.decode(bis), "128 not correctly decoded"); From 307e5fd56b58fafcd7d43a27369ee2874a5ecbb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ha=CC=8Avard=20Ottestad?= Date: Mon, 10 Jul 2023 09:58:32 +0200 Subject: [PATCH 2/2] optimize imports --- .../query/algebra/evaluation/iterator/HashJoinIteration.java | 1 - .../hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTParser.java | 1 - 2 files changed, 2 deletions(-) diff --git a/core/queryalgebra/evaluation/src/main/java/org/eclipse/rdf4j/query/algebra/evaluation/iterator/HashJoinIteration.java b/core/queryalgebra/evaluation/src/main/java/org/eclipse/rdf4j/query/algebra/evaluation/iterator/HashJoinIteration.java index 16a15e4efcf..c52e1f40814 100644 --- a/core/queryalgebra/evaluation/src/main/java/org/eclipse/rdf4j/query/algebra/evaluation/iterator/HashJoinIteration.java +++ b/core/queryalgebra/evaluation/src/main/java/org/eclipse/rdf4j/query/algebra/evaluation/iterator/HashJoinIteration.java @@ -26,7 +26,6 @@ import org.eclipse.rdf4j.common.iterator.EmptyIterator; import org.eclipse.rdf4j.common.iterator.UnionIterator; import org.eclipse.rdf4j.model.Value; -import org.eclipse.rdf4j.model.util.Values; import org.eclipse.rdf4j.query.BindingSet; import org.eclipse.rdf4j.query.MutableBindingSet; import org.eclipse.rdf4j.query.QueryEvaluationException; diff --git a/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTParser.java b/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTParser.java index 532f7bd33d9..7c54643a52c 100644 --- a/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTParser.java +++ b/core/rio/hdt/src/main/java/org/eclipse/rdf4j/rio/hdt/HDTParser.java @@ -10,7 +10,6 @@ *******************************************************************************/ package org.eclipse.rdf4j.rio.hdt; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.Reader;