Example usage for java.lang Integer MAX_VALUE

List of usage examples for java.lang Integer MAX_VALUE

Introduction

In this page you can find the example usage for java.lang Integer MAX_VALUE.

Prototype

int MAX_VALUE

To view the source code for java.lang Integer MAX_VALUE.

Click Source Link

Document

A constant holding the maximum value an int can have, 231-1.

Usage

From source file:melnorme.utilbox.misc.FileUtil.java

/** Read all bytes of the given file. 
 * @return the bytes that where read in a {@link java.io.ByteArrayOutputStream}. */
public static IByteSequence readBytesFromFile(File file) throws IOException, FileNotFoundException {
    long fileLength = file.length();
    /*//from  w  w  w . j av  a  2 s  . c om
     * You cannot create an array using a long type. It needs to be an
     * int type. Before converting to an int type, check to ensure
     * that file is not larger than Integer.MAX_VALUE.
     */
    if (fileLength > Integer.MAX_VALUE)
        throw new IOException("File is too large, size is bigger than " + Integer.MAX_VALUE);

    return StreamUtil.readAllBytesFromStream(new FileInputStream(file), (int) fileLength);
}

From source file:Main.java

/**
 * Multiply two integers, checking for overflow.
 * /*from w ww  .  ja va2 s  .c o  m*/
 * @param x a factor
 * @param y a factor
 * @return the product <code>x*y</code>
 * @throws ArithmeticException if the result can not be represented as an
 *         int
 * @since 1.1
 */
public static int mulAndCheck(int x, int y) {
    long m = ((long) x) * ((long) y);
    if (m < Integer.MIN_VALUE || m > Integer.MAX_VALUE) {
        throw new ArithmeticException("overflow: mul");
    }
    return (int) m;
}

From source file:Main.java

public static int copy(Reader input, Writer output) throws IOException {
    long count = copyLarge(input, output);
    if (count > Integer.MAX_VALUE) {
        return -1;
    }/*from   www.j  a v a  2  s.co  m*/
    return (int) count;
}

From source file:com.google.uzaygezen.core.ListConcatCombiner.java

public static <T extends Comparable<T>, V extends Content<V>, R extends Range<T, V>> ListConcatCombiner<T, V, R> unbounded() {
    return new ListConcatCombiner<>(Integer.MAX_VALUE);
}

From source file:myjpa.guest.model.Guests.java

public List<Guest> findAll() {
    //        return findAllNativeQuery();
    return findAll(0, Integer.MAX_VALUE);
}

From source file:org.glom.web.server.Utils.java

public static int safeLongToInt(final long value) {
    if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) {
        throw new IllegalArgumentException(value + " cannot be cast to int without changing its value.");
    }/*from www.jav  a  2  s.c o  m*/
    return (int) value;
}

From source file:SimpleIdGenerator.java

/**
 * Creates a new cycled id generator with specified initial value.
 *//*from   w w w . ja va  2 s .co  m*/
public SimpleIdGenerator(int initialValue) {
    this(initialValue, Integer.MAX_VALUE, true);
}

From source file:PNGDecoder.java

public static BufferedImage decode(InputStream in) throws IOException {
    DataInputStream dataIn = new DataInputStream(in);
    readSignature(dataIn);// w  w w  . j  a  v a  2 s  .c o m
    PNGData chunks = readChunks(dataIn);

    long widthLong = chunks.getWidth();
    long heightLong = chunks.getHeight();
    if (widthLong > Integer.MAX_VALUE || heightLong > Integer.MAX_VALUE)
        throw new IOException("That image is too wide or tall.");
    int width = (int) widthLong;
    int height = (int) heightLong;

    ColorModel cm = chunks.getColorModel();
    WritableRaster raster = chunks.getRaster();

    BufferedImage image = new BufferedImage(cm, raster, false, null);

    return image;
}

From source file:Main.java

public static ExecutorService fixedThreadsExecutor(String name, int count) {
    ThreadFactory threadFactory = daemonThreadFactory(name);

    return new ThreadPoolExecutor(count, count, 10, TimeUnit.SECONDS,
            new LinkedBlockingQueue<Runnable>(Integer.MAX_VALUE), threadFactory) {
        @Override//from ww w.j a v a2 s  .  co m
        protected void afterExecute(Runnable runnable, Throwable throwable) {
            if (throwable != null) {
                //Console.getInstance().info("Unexpected failure from " + runnable, throwable);
            }
        }
    };
}

From source file:io.github.seiferma.jameica.hibiscus.dkb.creditcard.util.DateUtils.java

public static Date getDateAgo(Unit unit, int amount) {
    Validate.inclusiveBetween(0, Integer.MAX_VALUE, amount);

    Calendar calendar = new GregorianCalendar();
    calendar.add(unit.getCalendarField(), -amount);
    return calendar.getTime();
}