source: josm/trunk/src/com/drew/lang/BufferBoundsException.java@ 6372

Last change on this file since 6372 was 6127, checked in by bastiK, 11 years ago

applied #8895 - Upgrade metadata-extractor to v. 2.6.4 (patch by ebourg)

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 1.9 KB
Line 
1/*
2 * Copyright 2002-2012 Drew Noakes
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * More information about this project is available at:
17 *
18 * http://drewnoakes.com/code/exif/
19 * http://code.google.com/p/metadata-extractor/
20 */
21
22package com.drew.lang;
23
24import com.drew.lang.annotations.NotNull;
25
26import java.io.IOException;
27
28/**
29 * A checked replacement for IndexOutOfBoundsException. Used by BufferReader.
30 *
31 * @author Drew Noakes http://drewnoakes.com
32 */
33public final class BufferBoundsException extends Exception
34{
35 private static final long serialVersionUID = 2911102837808946396L;
36
37 public BufferBoundsException(@NotNull byte[] buffer, int index, int bytesRequested)
38 {
39 super(getMessage(buffer, index, bytesRequested));
40 }
41
42 public BufferBoundsException(final String message)
43 {
44 super(message);
45 }
46
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)
53 {
54 if (index < 0)
55 return String.format("Attempt to read from buffer using a negative index (%s)", index);
56
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);
59 }
60}
Note: See TracBrowser for help on using the repository browser.