Changeset 13061 in josm for trunk/src/com/drew/lang
- Timestamp:
- 2017-10-30T22:46:09+01:00 (8 years ago)
- Location:
- trunk/src/com/drew/lang
- Files:
-
- 4 added
- 2 deleted
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/com/drew/lang/BufferBoundsException.java
r10862 r13061 1 1 /* 2 * Copyright 2002-201 6Drew Noakes2 * Copyright 2002-2017 Drew Noakes 3 3 * 4 4 * Licensed under the Apache License, Version 2.0 (the "License"); -
trunk/src/com/drew/lang/ByteArrayReader.java
r10862 r13061 1 1 /* 2 * Copyright 2002-201 6Drew Noakes2 * Copyright 2002-2017 Drew Noakes 3 3 * 4 4 * Licensed under the Apache License, Version 2.0 (the "License"); … … 22 22 package com.drew.lang; 23 23 24 import com.drew.lang.annotations.NotNull; 25 24 26 import java.io.IOException; 25 26 import com.drew.lang.annotations.NotNull;27 27 28 28 /** … … 39 39 @NotNull 40 40 private final byte[] _buffer; 41 private final int _baseOffset; 41 42 43 @SuppressWarnings({ "ConstantConditions" }) 44 @com.drew.lang.annotations.SuppressWarnings(value = "EI_EXPOSE_REP2", justification = "Design intent") 42 45 public ByteArrayReader(@NotNull byte[] buffer) 46 { 47 this(buffer, 0); 48 } 49 50 @SuppressWarnings({ "ConstantConditions" }) 51 @com.drew.lang.annotations.SuppressWarnings(value = "EI_EXPOSE_REP2", justification = "Design intent") 52 public ByteArrayReader(@NotNull byte[] buffer, int baseOffset) 43 53 { 44 54 if (buffer == null) 45 55 throw new NullPointerException(); 56 if (baseOffset < 0) 57 throw new IllegalArgumentException("Must be zero or greater"); 46 58 47 59 _buffer = buffer; 60 _baseOffset = baseOffset; 61 } 62 63 @Override 64 public int toUnshiftedOffset(int localOffset) 65 { 66 return localOffset + _baseOffset; 48 67 } 49 68 … … 51 70 public long getLength() 52 71 { 53 return _buffer.length; 72 return _buffer.length - _baseOffset; 54 73 } 55 74 56 75 @Override 57 p rotectedbyte getByte(int index) throws IOException76 public byte getByte(int index) throws IOException 58 77 { 59 return _buffer[index]; 78 validateIndex(index, 1); 79 return _buffer[index + _baseOffset]; 60 80 } 61 81 … … 64 84 { 65 85 if (!isValidIndex(index, bytesRequested)) 66 throw new BufferBoundsException( index, bytesRequested, _buffer.length);86 throw new BufferBoundsException(toUnshiftedOffset(index), bytesRequested, _buffer.length); 67 87 } 68 88 … … 72 92 return bytesRequested >= 0 73 93 && index >= 0 74 && (long)index + (long)bytesRequested - 1L < _buffer.length;94 && (long)index + (long)bytesRequested - 1L < getLength(); 75 95 } 76 96 … … 82 102 83 103 byte[] bytes = new byte[count]; 84 System.arraycopy(_buffer, index, bytes, 0, count); 104 System.arraycopy(_buffer, index + _baseOffset, bytes, 0, count); 85 105 return bytes; 86 106 } -
trunk/src/com/drew/lang/CompoundException.java
r10862 r13061 1 1 /* 2 * Copyright 2002-201 6Drew Noakes2 * Copyright 2002-2017 Drew Noakes 3 3 * 4 4 * Licensed under the Apache License, Version 2.0 (the "License"); -
trunk/src/com/drew/lang/GeoLocation.java
r10862 r13061 1 1 /* 2 * Copyright 2002-201 6Drew Noakes2 * Copyright 2002-2017 Drew Noakes 3 3 * 4 4 * Licensed under the Apache License, Version 2.0 (the "License"); -
trunk/src/com/drew/lang/RandomAccessReader.java
r10862 r13061 1 1 /* 2 * Copyright 2002-201 6Drew Noakes2 * Copyright 2002-2017 Drew Noakes 3 3 * 4 4 * Licensed under the Apache License, Version 2.0 (the "License"); … … 22 22 package com.drew.lang; 23 23 24 import com.drew.lang.annotations.NotNull;25 26 24 import java.io.IOException; 27 25 import java.io.UnsupportedEncodingException; 26 import java.nio.charset.Charset; 27 28 import com.drew.lang.annotations.NotNull; 29 import com.drew.lang.annotations.Nullable; 30 import com.drew.metadata.StringValue; 28 31 29 32 /** … … 36 39 * <ul> 37 40 * <li>{@link ByteArrayReader}</li> 38 * <li>{@link RandomAccessStreamReader}</li>39 41 * </ul> 40 42 * … … 45 47 private boolean _isMotorolaByteOrder = true; 46 48 49 public abstract int toUnshiftedOffset(int localOffset); 50 47 51 /** 48 52 * Gets the byte value at the specified byte <code>index</code>. … … 57 61 * @throws IOException if the byte is unable to be read 58 62 */ 59 p rotectedabstract byte getByte(int index) throws IOException;63 public abstract byte getByte(int index) throws IOException; 60 64 61 65 /** … … 89 93 * Returns the length of the data source in bytes. 90 94 * <p> 91 * This is a simple operation for implementations (such as {@link RandomAccessFileReader} and95 * This is a simple operation for implementations (such as 92 96 * {@link ByteArrayReader}) that have the entire data source available. 93 97 * <p> 94 * Users of this method must be aware that sequentially accessed implementations such as95 * {@link RandomAccessStreamReader}will have to read and buffer the entire data source in98 * Users of this method must be aware that sequentially accessed implementations 99 * will have to read and buffer the entire data source in 96 100 * order to determine the length. 97 101 * … … 207 211 if (_isMotorolaByteOrder) { 208 212 // Motorola - MSB first 209 return (short) (( (short)getByte(index ) << 8 & (short)0xFF00) |210 ( (short)getByte(index + 1) & (short)0xFF));213 return (short) ((getByte(index ) << 8 & (short)0xFF00) | 214 (getByte(index + 1) & (short)0xFF)); 211 215 } else { 212 216 // Intel ordering - LSB first 213 return (short) (( (short)getByte(index + 1) << 8 & (short)0xFF00) |214 ( (short)getByte(index ) & (short)0xFF));217 return (short) ((getByte(index + 1) << 8 & (short)0xFF00) | 218 (getByte(index ) & (short)0xFF)); 215 219 } 216 220 } … … 229 233 if (_isMotorolaByteOrder) { 230 234 // Motorola - MSB first (big endian) 231 return (( (int)getByte(index )) << 16 & 0xFF0000) |232 (( (int)getByte(index + 1)) << 8 & 0xFF00) |233 (( (int)getByte(index + 2)) & 0xFF);235 return ((getByte(index )) << 16 & 0xFF0000) | 236 ((getByte(index + 1)) << 8 & 0xFF00) | 237 ((getByte(index + 2)) & 0xFF); 234 238 } else { 235 239 // Intel ordering - LSB first (little endian) 236 return (( (int)getByte(index + 2)) << 16 & 0xFF0000) |237 (( (int)getByte(index + 1)) << 8 & 0xFF00) |238 (( (int)getByte(index )) & 0xFF);240 return ((getByte(index + 2)) << 16 & 0xFF0000) | 241 ((getByte(index + 1)) << 8 & 0xFF00) | 242 ((getByte(index )) & 0xFF); 239 243 } 240 244 } … … 256 260 (((long)getByte(index + 1)) << 16 & 0xFF0000L) | 257 261 (((long)getByte(index + 2)) << 8 & 0xFF00L) | 258 (( (long)getByte(index + 3)) & 0xFFL);262 ((getByte(index + 3)) & 0xFFL); 259 263 } else { 260 264 // Intel ordering - LSB first (little endian) … … 262 266 (((long)getByte(index + 2)) << 16 & 0xFF0000L) | 263 267 (((long)getByte(index + 1)) << 8 & 0xFF00L) | 264 (( (long)getByte(index )) & 0xFFL);268 ((getByte(index )) & 0xFFL); 265 269 } 266 270 } … … 312 316 ((long)getByte(index + 5) << 16 & 0xFF0000L) | 313 317 ((long)getByte(index + 6) << 8 & 0xFF00L) | 314 ( (long)getByte(index + 7) & 0xFFL);318 (getByte(index + 7) & 0xFFL); 315 319 } else { 316 320 // Intel ordering - LSB first … … 322 326 ((long)getByte(index + 2) << 16 & 0xFF0000L) | 323 327 ((long)getByte(index + 1) << 8 & 0xFF00L) | 324 ( (long)getByte(index ) & 0xFFL);328 (getByte(index ) & 0xFFL); 325 329 } 326 330 } … … 365 369 366 370 @NotNull 367 public String getString(int index, int bytesRequested) throws IOException 368 { 369 return new String(getBytes(index, bytesRequested)); 370 } 371 372 @NotNull 373 public String getString(int index, int bytesRequested, String charset) throws IOException 371 public StringValue getStringValue(int index, int bytesRequested, @Nullable Charset charset) throws IOException 372 { 373 return new StringValue(getBytes(index, bytesRequested), charset); 374 } 375 376 @NotNull 377 public String getString(int index, int bytesRequested, @NotNull Charset charset) throws IOException 378 { 379 return new String(getBytes(index, bytesRequested), charset.name()); 380 } 381 382 @NotNull 383 public String getString(int index, int bytesRequested, @NotNull String charset) throws IOException 374 384 { 375 385 byte[] bytes = getBytes(index, bytesRequested); … … 392 402 */ 393 403 @NotNull 394 public String getNullTerminatedString(int index, int maxLengthBytes) throws IOException 395 { 396 // NOTE currently only really suited to single-byte character strings 397 398 byte[] bytes = getBytes(index, maxLengthBytes); 404 public String getNullTerminatedString(int index, int maxLengthBytes, @NotNull Charset charset) throws IOException 405 { 406 return new String(getNullTerminatedBytes(index, maxLengthBytes), charset.name()); 407 } 408 409 @NotNull 410 public StringValue getNullTerminatedStringValue(int index, int maxLengthBytes, @Nullable Charset charset) throws IOException 411 { 412 byte[] bytes = getNullTerminatedBytes(index, maxLengthBytes); 413 414 return new StringValue(bytes, charset); 415 } 416 417 /** 418 * Returns the sequence of bytes punctuated by a <code>\0</code> value. 419 * 420 * @param index The index within the buffer at which to start reading the string. 421 * @param maxLengthBytes The maximum number of bytes to read. If a <code>\0</code> byte is not reached within this limit, 422 * the returned array will be <code>maxLengthBytes</code> long. 423 * @return The read byte array, excluding the null terminator. 424 * @throws IOException The buffer does not contain enough bytes to satisfy this request. 425 */ 426 @NotNull 427 public byte[] getNullTerminatedBytes(int index, int maxLengthBytes) throws IOException 428 { 429 byte[] buffer = getBytes(index, maxLengthBytes); 399 430 400 431 // Count the number of non-null bytes 401 432 int length = 0; 402 while (length < b ytes.length && bytes[length] !='\0')433 while (length < buffer.length && buffer[length] != 0) 403 434 length++; 404 435 405 return new String(bytes, 0, length); 436 if (length == maxLengthBytes) 437 return buffer; 438 439 byte[] bytes = new byte[length]; 440 if (length > 0) 441 System.arraycopy(buffer, 0, bytes, 0, length); 442 return bytes; 406 443 } 407 444 } -
trunk/src/com/drew/lang/Rational.java
r10862 r13061 1 1 /* 2 * Copyright 2002-201 6Drew Noakes2 * Copyright 2002-2017 Drew Noakes 3 3 * 4 4 * Licensed under the Apache License, Version 2.0 (the "License"); … … 36 36 * @author Drew Noakes https://drewnoakes.com 37 37 */ 38 public class Rational extends java.lang.Number implements Serializable 38 @SuppressWarnings("WeakerAccess") 39 public class Rational extends java.lang.Number implements Comparable<Rational>, Serializable 39 40 { 40 41 private static final long serialVersionUID = 510688928138848770L; … … 173 174 (_denominator != 0 && (_numerator % _denominator == 0)) || 174 175 (_denominator == 0 && _numerator == 0); 176 } 177 178 /** Checks if either the numerator or denominator are zero. */ 179 public boolean isZero() 180 { 181 return _numerator == 0 || _denominator == 0; 175 182 } 176 183 … … 212 219 213 220 /** 214 * Decides whether a brute-force simplification calculation should be avoided 215 * by comparing the maximum number of possible calculations with some threshold. 216 * 217 * @return true if the simplification should be performed, otherwise false 218 */ 219 private boolean tooComplexForSimplification() 220 { 221 double maxPossibleCalculations = (((double) (Math.min(_denominator, _numerator) - 1) / 5d) + 2); 222 final int maxSimplificationCalculations = 1000; 223 return maxPossibleCalculations > maxSimplificationCalculations; 221 * Compares two {@link Rational} instances, returning true if they are mathematically 222 * equivalent (in consistence with {@link Rational#equals(Object)} method). 223 * 224 * @param that the {@link Rational} to compare this instance to. 225 * @return the value {@code 0} if this {@link Rational} is 226 * equal to the argument {@link Rational} mathematically; a value less 227 * than {@code 0} if this {@link Rational} is less 228 * than the argument {@link Rational}; and a value greater 229 * than {@code 0} if this {@link Rational} is greater than the argument 230 * {@link Rational}. 231 */ 232 public int compareTo(@NotNull Rational that) { 233 return Double.compare(this.doubleValue(), that.doubleValue()); 234 } 235 236 /** 237 * Indicates whether this instance and <code>other</code> are numerically equal, 238 * even if their representations differ. 239 * 240 * For example, 1/2 is equal to 10/20 by this method. 241 * Similarly, 1/0 is equal to 100/0 by this method. 242 * To test equal representations, use EqualsExact. 243 * 244 * @param other The rational value to compare with 245 */ 246 public boolean equals(Rational other) { 247 return other.doubleValue() == doubleValue(); 248 } 249 250 /** 251 * Indicates whether this instance and <code>other</code> have identical 252 * Numerator and Denominator. 253 * <p> 254 * For example, 1/2 is not equal to 10/20 by this method. 255 * Similarly, 1/0 is not equal to 100/0 by this method. 256 * To test numerically equivalence, use Equals(Rational).</p> 257 * 258 * @param other The rational value to compare with 259 */ 260 public boolean equalsExact(Rational other) { 261 return getDenominator() == other.getDenominator() && getNumerator() == other.getNumerator(); 224 262 } 225 263 … … 249 287 /** 250 288 * <p> 251 * Simplifies the {@link Rational} number.</p> 289 * Simplifies the representation of this {@link Rational} number.</p> 252 290 * <p> 253 * Prime number series: 1, 2, 3, 5, 7, 9, 11, 13, 17</p> 291 * For example, 5/10 simplifies to 1/2 because both Numerator 292 * and Denominator share a common factor of 5.</p> 254 293 * <p> 255 * To reduce a rational, need to see if both numerator and denominator are divisible 256 * by a common factor. Using the prime number series in ascending order guarantees 257 * the minimum number of checks required.</p> 258 * <p> 259 * However, generating the prime number series seems to be a hefty task. Perhaps 260 * it's simpler to check if both d & n are divisible by all numbers from 2 {@literal ->} 261 * (Math.min(denominator, numerator) / 2). In doing this, one can check for 2 262 * and 5 once, then ignore all even numbers, and all numbers ending in 0 or 5. 263 * This leaves four numbers from every ten to check.</p> 264 * <p> 265 * Therefore, the max number of pairs of modulus divisions required will be:</p> 266 * <pre><code> 267 * 4 Math.min(denominator, numerator) - 1 268 * -- * ------------------------------------ + 2 269 * 10 2 270 * 271 * Math.min(denominator, numerator) - 1 272 * = ------------------------------------ + 2 273 * 5 274 * </code></pre> 275 * 276 * @return a simplified instance, or if the Rational could not be simplified, 277 * returns itself (unchanged) 294 * Uses the Euclidean Algorithm to find the greatest common divisor.</p> 295 * 296 * @return A simplified instance if one exists, otherwise a copy of the original value. 278 297 */ 279 298 @NotNull 280 299 public Rational getSimplifiedInstance() 281 300 { 282 if (tooComplexForSimplification()) { 283 return this; 301 long gcd = GCD(_numerator, _denominator); 302 303 return new Rational(_numerator / gcd, _denominator / gcd); 304 } 305 306 private static long GCD(long a, long b) 307 { 308 if (a < 0) 309 a = -a; 310 if (b < 0) 311 b = -b; 312 313 while (a != 0 && b != 0) 314 { 315 if (a > b) 316 a %= b; 317 else 318 b %= a; 284 319 } 285 for (int factor = 2; factor <= Math.min(_denominator, _numerator); factor++) { 286 if ((factor % 2 == 0 && factor > 2) || (factor % 5 == 0 && factor > 5)) { 287 continue; 288 } 289 if (_denominator % factor == 0 && _numerator % factor == 0) { 290 // found a common factor 291 return new Rational(_numerator / factor, _denominator / factor); 292 } 293 } 294 return this; 320 321 return a == 0 ? b : a; 295 322 } 296 323 } -
trunk/src/com/drew/lang/SequentialByteArrayReader.java
r10862 r13061 1 1 /* 2 * Copyright 2002-201 6Drew Noakes2 * Copyright 2002-2017 Drew Noakes 3 3 * 4 4 * Licensed under the Apache License, Version 2.0 (the "License"); … … 37 37 private int _index; 38 38 39 @Override 40 public long getPosition() 41 { 42 return _index; 43 } 44 39 45 public SequentialByteArrayReader(@NotNull byte[] bytes) 40 46 { … … 42 48 } 43 49 50 @SuppressWarnings("ConstantConditions") 44 51 public SequentialByteArrayReader(@NotNull byte[] bytes, int baseIndex) 45 52 { … … 52 59 53 60 @Override 54 p rotectedbyte getByte() throws IOException61 public byte getByte() throws IOException 55 62 { 56 63 if (_index >= _bytes.length) { … … 73 80 74 81 return bytes; 82 } 83 84 @Override 85 public void getBytes(@NotNull byte[] buffer, int offset, int count) throws IOException 86 { 87 if (_index + count > _bytes.length) { 88 throw new EOFException("End of data reached."); 89 } 90 91 System.arraycopy(_bytes, _index, buffer, offset, count); 92 _index += count; 75 93 } 76 94 … … 105 123 return true; 106 124 } 125 126 @Override 127 public int available() { 128 return _bytes.length - _index; 129 } 107 130 } -
trunk/src/com/drew/lang/SequentialReader.java
r10862 r13061 1 1 /* 2 * Copyright 2002-201 6Drew Noakes2 * Copyright 2002-2017 Drew Noakes 3 3 * 4 4 * Licensed under the Apache License, Version 2.0 (the "License"); … … 23 23 24 24 import com.drew.lang.annotations.NotNull; 25 import com.drew.lang.annotations.Nullable; 26 import com.drew.metadata.StringValue; 25 27 26 28 import java.io.EOFException; 27 29 import java.io.IOException; 28 30 import java.io.UnsupportedEncodingException; 31 import java.nio.charset.Charset; 29 32 30 33 /** 31 34 * @author Drew Noakes https://drewnoakes.com 32 35 */ 36 @SuppressWarnings("WeakerAccess") 33 37 public abstract class SequentialReader 34 38 { … … 37 41 private boolean _isMotorolaByteOrder = true; 38 42 43 public abstract long getPosition() throws IOException; 44 39 45 /** 40 46 * Gets the next byte in the sequence. … … 42 48 * @return The read byte value 43 49 */ 44 p rotectedabstract byte getByte() throws IOException;50 public abstract byte getByte() throws IOException; 45 51 46 52 /** … … 52 58 @NotNull 53 59 public abstract byte[] getBytes(int count) throws IOException; 60 61 /** 62 * Retrieves bytes, writing them into a caller-provided buffer. 63 * @param buffer The array to write bytes to. 64 * @param offset The starting position within buffer to write to. 65 * @param count The number of bytes to be written. 66 */ 67 public abstract void getBytes(@NotNull byte[] buffer, int offset, int count) throws IOException; 54 68 55 69 /** … … 70 84 */ 71 85 public abstract boolean trySkip(long n) throws IOException; 86 87 /** 88 * Returns an estimate of the number of bytes that can be read (or skipped 89 * over) from this {@link SequentialReader} without blocking by the next 90 * invocation of a method for this input stream. A single read or skip of 91 * this many bytes will not block, but may read or skip fewer bytes. 92 * <p> 93 * Note that while some implementations of {@link SequentialReader} like 94 * {@link SequentialByteArrayReader} will return the total remaining number 95 * of bytes in the stream, others will not. It is never correct to use the 96 * return value of this method to allocate a buffer intended to hold all 97 * data in this stream. 98 * 99 * @return an estimate of the number of bytes that can be read (or skipped 100 * over) from this {@link SequentialReader} without blocking or 101 * {@code 0} when it reaches the end of the input stream. 102 */ 103 public abstract int available(); 72 104 73 105 /** … … 284 316 } 285 317 318 @NotNull 319 public String getString(int bytesRequested, @NotNull Charset charset) throws IOException 320 { 321 byte[] bytes = getBytes(bytesRequested); 322 return new String(bytes, charset); 323 } 324 325 @NotNull 326 public StringValue getStringValue(int bytesRequested, @Nullable Charset charset) throws IOException 327 { 328 return new StringValue(getBytes(bytesRequested), charset); 329 } 330 286 331 /** 287 332 * Creates a String from the stream, ending where <code>byte=='\0'</code> or where <code>length==maxLength</code>. … … 293 338 */ 294 339 @NotNull 295 public String getNullTerminatedString(int maxLengthBytes) throws IOException 296 { 297 // NOTE currently only really suited to single-byte character strings 298 299 byte[] bytes = new byte[maxLengthBytes]; 340 public String getNullTerminatedString(int maxLengthBytes, Charset charset) throws IOException 341 { 342 return getNullTerminatedStringValue(maxLengthBytes, charset).toString(); 343 } 344 345 /** 346 * Creates a String from the stream, ending where <code>byte=='\0'</code> or where <code>length==maxLength</code>. 347 * 348 * @param maxLengthBytes The maximum number of bytes to read. If a <code>\0</code> byte is not reached within this limit, 349 * reading will stop and the string will be truncated to this length. 350 * @param charset The <code>Charset</code> to register with the returned <code>StringValue</code>, or <code>null</code> if the encoding 351 * is unknown 352 * @return The read string. 353 * @throws IOException The buffer does not contain enough bytes to satisfy this request. 354 */ 355 @NotNull 356 public StringValue getNullTerminatedStringValue(int maxLengthBytes, Charset charset) throws IOException 357 { 358 byte[] bytes = getNullTerminatedBytes(maxLengthBytes); 359 360 return new StringValue(bytes, charset); 361 } 362 363 /** 364 * Returns the sequence of bytes punctuated by a <code>\0</code> value. 365 * 366 * @param maxLengthBytes The maximum number of bytes to read. If a <code>\0</code> byte is not reached within this limit, 367 * the returned array will be <code>maxLengthBytes</code> long. 368 * @return The read byte array, excluding the null terminator. 369 * @throws IOException The buffer does not contain enough bytes to satisfy this request. 370 */ 371 @NotNull 372 public byte[] getNullTerminatedBytes(int maxLengthBytes) throws IOException 373 { 374 byte[] buffer = new byte[maxLengthBytes]; 300 375 301 376 // Count the number of non-null bytes 302 377 int length = 0; 303 while (length < b ytes.length && (bytes[length] = getByte()) !='\0')378 while (length < buffer.length && (buffer[length] = getByte()) != 0) 304 379 length++; 305 380 306 return new String(bytes, 0, length); 381 if (length == maxLengthBytes) 382 return buffer; 383 384 byte[] bytes = new byte[length]; 385 if (length > 0) 386 System.arraycopy(buffer, 0, bytes, 0, length); 387 return bytes; 307 388 } 308 389 } -
trunk/src/com/drew/lang/StreamReader.java
r10862 r13061 1 1 /* 2 * Copyright 2002-201 6Drew Noakes2 * Copyright 2002-2017 Drew Noakes 3 3 * 4 4 * Licensed under the Apache License, Version 2.0 (the "License"); … … 37 37 private final InputStream _stream; 38 38 39 private long _pos; 40 41 @Override 42 public long getPosition() 43 { 44 return _pos; 45 } 46 47 @SuppressWarnings("ConstantConditions") 39 48 public StreamReader(@NotNull InputStream stream) 40 49 { … … 43 52 44 53 _stream = stream; 54 _pos = 0; 45 55 } 46 56 47 57 @Override 48 p rotectedbyte getByte() throws IOException58 public byte getByte() throws IOException 49 59 { 50 60 int value = _stream.read(); 51 61 if (value == -1) 52 62 throw new EOFException("End of data reached."); 63 _pos++; 53 64 return (byte)value; 54 65 } … … 59 70 { 60 71 byte[] bytes = new byte[count]; 72 getBytes(bytes, 0, count); 73 return bytes; 74 } 75 76 @Override 77 public void getBytes(@NotNull byte[] buffer, int offset, int count) throws IOException 78 { 61 79 int totalBytesRead = 0; 62 63 while (totalBytesRead != count){64 final int bytesRead = _stream.read(b ytes,totalBytesRead, count - totalBytesRead);80 while (totalBytesRead != count) 81 { 82 final int bytesRead = _stream.read(buffer, offset + totalBytesRead, count - totalBytesRead); 65 83 if (bytesRead == -1) 66 84 throw new EOFException("End of data reached."); … … 68 86 assert(totalBytesRead <= count); 69 87 } 70 71 return bytes; 88 _pos += totalBytesRead; 72 89 } 73 90 … … 93 110 } 94 111 112 @Override 113 public int available() { 114 try { 115 return _stream.available(); 116 } catch (IOException e) { 117 return 0; 118 } 119 } 120 95 121 private long skipInternal(long n) throws IOException 96 122 { … … 109 135 break; 110 136 } 137 _pos += skippedTotal; 111 138 return skippedTotal; 112 139 } -
trunk/src/com/drew/lang/StringUtil.java
r10862 r13061 1 1 /* 2 * Copyright 2002-201 6Drew Noakes2 * Copyright 2002-2017 Drew Noakes 3 3 * 4 4 * Licensed under the Apache License, Version 2.0 (the "License"); … … 34 34 * @author Drew Noakes https://drewnoakes.com 35 35 */ 36 public class StringUtil 36 public final class StringUtil 37 37 { 38 38 @NotNull -
trunk/src/com/drew/lang/annotations/NotNull.java
r10862 r13061 1 1 /* 2 * Copyright 2002-201 6Drew Noakes2 * Copyright 2002-2017 Drew Noakes 3 3 * 4 4 * Licensed under the Apache License, Version 2.0 (the "License"); -
trunk/src/com/drew/lang/annotations/Nullable.java
r10862 r13061 1 1 /* 2 * Copyright 2002-201 6Drew Noakes2 * Copyright 2002-2017 Drew Noakes 3 3 * 4 4 * Licensed under the Apache License, Version 2.0 (the "License");
Note:
See TracChangeset
for help on using the changeset viewer.