Ignore:
Timestamp:
2015-03-10T01:17:39+01:00 (9 years ago)
Author:
Don-vip
Message:

fix #11162 - update to metadata-extractor 2.7.2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/com/drew/lang/BufferBoundsException.java

    r6127 r8132  
    11/*
    2  * Copyright 2002-2012 Drew Noakes
     2 * Copyright 2002-2015 Drew Noakes
    33 *
    44 *    Licensed under the Apache License, Version 2.0 (the "License");
     
    1616 * More information about this project is available at:
    1717 *
    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
    2020 */
    2121
    2222package com.drew.lang;
    2323
    24 import com.drew.lang.annotations.NotNull;
    25 
    2624import java.io.IOException;
    2725
    2826/**
    29  * A checked replacement for IndexOutOfBoundsException.  Used by BufferReader.
    30  * 
    31  * @author Drew Noakes http://drewnoakes.com
     27 * A checked replacement for {@link IndexOutOfBoundsException}.  Used by {@link RandomAccessReader}.
     28 *
     29 * @author Drew Noakes https://drewnoakes.com
    3230 */
    33 public final class BufferBoundsException extends Exception
     31public final class BufferBoundsException extends IOException
    3432{
    3533    private static final long serialVersionUID = 2911102837808946396L;
    3634
    37     public BufferBoundsException(@NotNull byte[] buffer, int index, int bytesRequested)
     35    public BufferBoundsException(int index, int bytesRequested, long bufferLength)
    3836    {
    39         super(getMessage(buffer, index, bytesRequested));
     37        super(getMessage(index, bytesRequested, bufferLength));
    4038    }
    4139
     
    4543    }
    4644
    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)
    5346    {
    5447        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);
    5649
    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);
    5958    }
    6059}
Note: See TracChangeset for help on using the changeset viewer.