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

Last change on this file since 12288 was 10862, checked in by Don-vip, 8 years ago

update to metadata-extractor 2.9.1

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 2.2 KB
Line 
1/*
2 * Copyright 2002-2016 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 * https://drewnoakes.com/code/exif/
19 * https://github.com/drewnoakes/metadata-extractor
20 */
21
22package com.drew.lang;
23
24import java.io.IOException;
25
26/**
27 * A checked replacement for {@link IndexOutOfBoundsException}. Used by {@link RandomAccessReader}.
28 *
29 * @author Drew Noakes https://drewnoakes.com
30 */
31public final class BufferBoundsException extends IOException
32{
33 private static final long serialVersionUID = 2911102837808946396L;
34
35 public BufferBoundsException(int index, int bytesRequested, long bufferLength)
36 {
37 super(getMessage(index, bytesRequested, bufferLength));
38 }
39
40 public BufferBoundsException(final String message)
41 {
42 super(message);
43 }
44
45 private static String getMessage(int index, int bytesRequested, long bufferLength)
46 {
47 if (index < 0)
48 return String.format("Attempt to read from buffer using a negative index (%d)", index);
49
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);
58 }
59}
Note: See TracBrowser for help on using the repository browser.