Changeset 8132 in josm for trunk/src/com/drew/lang/BufferBoundsException.java
- Timestamp:
- 2015-03-10T01:17:39+01:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/com/drew/lang/BufferBoundsException.java
r6127 r8132 1 1 /* 2 * Copyright 2002-201 2Drew Noakes2 * Copyright 2002-2015 Drew Noakes 3 3 * 4 4 * Licensed under the Apache License, Version 2.0 (the "License"); … … 16 16 * More information about this project is available at: 17 17 * 18 * http ://drewnoakes.com/code/exif/19 * http ://code.google.com/p/metadata-extractor/18 * https://drewnoakes.com/code/exif/ 19 * https://github.com/drewnoakes/metadata-extractor 20 20 */ 21 21 22 22 package com.drew.lang; 23 23 24 import com.drew.lang.annotations.NotNull;25 26 24 import java.io.IOException; 27 25 28 26 /** 29 * A checked replacement for IndexOutOfBoundsException. Used by BufferReader.30 * 31 * @author Drew Noakes http ://drewnoakes.com27 * A checked replacement for {@link IndexOutOfBoundsException}. Used by {@link RandomAccessReader}. 28 * 29 * @author Drew Noakes https://drewnoakes.com 32 30 */ 33 public final class BufferBoundsException extends Exception31 public final class BufferBoundsException extends IOException 34 32 { 35 33 private static final long serialVersionUID = 2911102837808946396L; 36 34 37 public BufferBoundsException( @NotNull byte[] buffer, int index, int bytesRequested)35 public BufferBoundsException(int index, int bytesRequested, long bufferLength) 38 36 { 39 super(getMessage( buffer, index, bytesRequested));37 super(getMessage(index, bytesRequested, bufferLength)); 40 38 } 41 39 … … 45 43 } 46 44 47 public BufferBoundsException(final String message, final IOException innerException) 48 { 49 super(message, innerException); 50 } 51 52 private static String getMessage(@NotNull byte[] buffer, int index, int bytesRequested) 45 private static String getMessage(int index, int bytesRequested, long bufferLength) 53 46 { 54 47 if (index < 0) 55 return String.format("Attempt to read from buffer using a negative index (% s)", index);48 return String.format("Attempt to read from buffer using a negative index (%d)", index); 56 49 57 return String.format("Attempt to read %d byte%s from beyond end of buffer (requested index: %d, max index: %d)", 58 bytesRequested, bytesRequested==1?"":"s", index, buffer.length - 1); 50 if (bytesRequested < 0) 51 return String.format("Number of requested bytes cannot be negative (%d)", bytesRequested); 52 53 if ((long)index + (long)bytesRequested - 1L > (long)Integer.MAX_VALUE) 54 return String.format("Number of requested bytes summed with starting index exceed maximum range of signed 32 bit integers (requested index: %d, requested count: %d)", index, bytesRequested); 55 56 return String.format("Attempt to read from beyond end of underlying data source (requested index: %d, requested count: %d, max index: %d)", 57 index, bytesRequested, bufferLength - 1); 59 58 } 60 59 }
Note:
See TracChangeset
for help on using the changeset viewer.