Better name for "tribyte" -> "medium"

This commit is contained in:
atomicint
2015-03-29 12:33:39 -04:00
parent 1f2fde61a8
commit 7f345fffac
2 changed files with 14 additions and 14 deletions
+4 -4
View File
@@ -22,8 +22,8 @@ public final class Archive {
* @throws IOException If there is an error decompressing the archive.
*/
public static Archive decode(ByteBuffer buffer) throws IOException {
int extractedSize = BufferUtil.readUnsignedTriByte(buffer);
int size = BufferUtil.readUnsignedTriByte(buffer);
int extractedSize = BufferUtil.readUnsignedMedium(buffer);
int size = BufferUtil.readUnsignedMedium(buffer);
boolean extracted = false;
if (size != extractedSize) {
@@ -42,8 +42,8 @@ public final class Archive {
for (int i = 0; i < entryCount; i++) {
identifiers[i] = buffer.getInt();
extractedSizes[i] = BufferUtil.readUnsignedTriByte(buffer);
sizes[i] = BufferUtil.readUnsignedTriByte(buffer);
extractedSizes[i] = BufferUtil.readUnsignedMedium(buffer);
sizes[i] = BufferUtil.readUnsignedMedium(buffer);
}
ArchiveEntry[] entries = new ArchiveEntry[entryCount];
+10 -10
View File
@@ -20,11 +20,10 @@ public final class BufferUtil {
* @return The 'smart'.
*/
public static int readSmart(ByteBuffer buffer) {
// Reads a single byte from the buffer without modifying the current position.
int peek = buffer.get(buffer.position()) & 0xFF;
if (peek < 128) {
return buffer.get() & 0xFF;
}
return (buffer.getShort() & 0xFFFF) - 32768;
int value = peek > Byte.MAX_VALUE ? (buffer.getShort() & 0xFFFF) + Short.MIN_VALUE : buffer.get() & 0xFF;
return value;
}
/**
@@ -58,13 +57,14 @@ public final class BufferUtil {
}
/**
* Reads an unsigned tri-byte from the specified {@link ByteBuffer}.
*
* @param buffer The buffer.
* @return The tri-byte.
* Reads a 24-bit medium integer from the specified {@link ByteBuffer}s current position and increases the buffers
* position by 3.
*
* @param buffer The {@link ByteBuffer} to read from.
* @return The read 24-bit medium integer.
*/
public static int readUnsignedTriByte(ByteBuffer buffer) {
return (buffer.get() & 0xFF) << 16 | (buffer.get() & 0xFF) << 8 | buffer.get() & 0xFF;
public static int readUnsignedMedium(ByteBuffer buffer) {
return (buffer.getShort() & 0xFFFF) << 8 | buffer.get() & 0xFF;
}
/**