diff --git a/crawler4j/src/main/java/edu/uci/ics/crawler4j/frontier/WorkQueues.java b/crawler4j/src/main/java/edu/uci/ics/crawler4j/frontier/WorkQueues.java index eeb474d03..232c05d9d 100644 --- a/crawler4j/src/main/java/edu/uci/ics/crawler4j/frontier/WorkQueues.java +++ b/crawler4j/src/main/java/edu/uci/ics/crawler4j/frontier/WorkQueues.java @@ -122,7 +122,18 @@ public void delete(int count) { */ protected static DatabaseEntry getDatabaseEntryKey(WebURL url) { byte[] keyData = new byte[6]; - keyData[0] = url.getPriority(); + byte priority = url.getPriority(); + if (priority < 0) { + throw new IllegalArgumentException("Priority must be non-negative"); + } + keyData[0] = priority; + + // second option-- use this function + // protected static int unsignedByteToInt(byte b) { + // return b & 0xFF; // Converts signed byte to unsigned int + // } + // int priority = unsignedByteToInt(keyData[0]); + keyData[1] = ((url.getDepth() > Byte.MAX_VALUE) ? Byte.MAX_VALUE : (byte) url.getDepth()); Util.putIntInByteArray(url.getDocid(), keyData, 2); return new DatabaseEntry(keyData);