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:Main.java

public static boolean isServiceRunning(Context context, Class<?> serviceClass) {
    final ActivityManager activityManager = (ActivityManager) context
            .getSystemService(Context.ACTIVITY_SERVICE);
    final List<ActivityManager.RunningServiceInfo> services = activityManager
            .getRunningServices(Integer.MAX_VALUE);
    for (ActivityManager.RunningServiceInfo runningServiceInfo : services) {
        if (runningServiceInfo.service.getClassName().equals(serviceClass.getName())) {
            return true;
        }/*from   www  .  j  ava 2  s . c  o  m*/
    }
    return false;
}

From source file:Main.java

/**
 * Check if a service is running/*from   w w  w  .j a  v  a 2 s . c  o  m*/
 * @param context
 * @param serviceClassName - complete name of service
 * @return
 */
public static boolean isServiceRunning(Context context, String serviceClassName) {
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (serviceClassName.equals(service.service.getClassName())) {
            return true;
        }
    }
    return false;
}

From source file:Main.java

/**
 * Decodes from an input stream that optimally supports mark and reset
 * operations. If a maximum width and/or height are specified then the
 * passed stream must support mark and reset so that the bitmap can be down
 * sampled properly. If the width and/or height are specified and the input
 * stream does not support mark and reset, then an IllegalArgumentException
 * will be throw./*from   w  w w  . ja va 2s .co  m*/
 */
public static Bitmap decodeSampledBitmapFromStream(InputStream inputStream, int width, int height) {
    if ((width != 0 || height != 0) && !inputStream.markSupported()) {
        throw new IllegalArgumentException(
                "Bitmap decoding requires an input stream that supports " + "mark and reset");
    }

    // Set a mark for reset. Since we have no idea of the size of this
    // image, just set the maximum value possible.
    inputStream.mark(Integer.MAX_VALUE);

    // First decode with inJustDecodeBounds=true to check dimensions.
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeStream(inputStream, null, options);

    // Reset the stream for the actual decoding phase.
    try {
        inputStream.reset();
    } catch (IOException e) {
        Log.e(TAG, "Failed to reset input stream during bitmap decoding");
        return null;
    }

    // If either width or height is passed in as 0, then use the actual
    // stored image dimension.
    if (width == 0) {
        width = options.outWidth;
    }
    if (height == 0) {
        height = options.outHeight;
    }

    // Calculate inSampleSize
    options.inSampleSize = calculateInSampleSize(options, width, height);

    // Decode bitmap with inSampleSize set
    options.inJustDecodeBounds = false;
    return BitmapFactory.decodeStream(inputStream, null, options);
}

From source file:Main.java

/**
 * Returns the index of the first instance of any of the charsToFind
 * @param s/*from www .  j a va2  s. c o  m*/
 * @param charsToFind
 * @param startIndex
 * @return
 */
public static int findNextOrEnd(String s, char[] charsToFind, int startIndex) {
    int position = Integer.MAX_VALUE;
    for (char ch : charsToFind) {
        int x = s.indexOf(ch, startIndex);
        if ((x != -1) && (x < position)) {
            position = x;
        }
    }

    // Wah wahhhh... didn't find what we were looking for
    if (position == Integer.MAX_VALUE) {
        position = s.length();
    }

    return position;
}

From source file:Main.java

public static boolean isPosible(Rectangle2D.Double r) {
    if ((r.getMaxX() > Integer.MAX_VALUE) || (r.getMaxY() > Integer.MAX_VALUE)
            || (r.getMinX() < Integer.MIN_VALUE) || (r.getMinY() < Integer.MIN_VALUE)
            || (r.getWidth() > Integer.MAX_VALUE) || (r.getHeight() > Integer.MAX_VALUE)) {
        return false;
    }//from  w w w .  j a v a 2s . co m

    return true;
}

From source file:Main.java

/**
 * Indicates if the service given by <tt>activityClass</tt> is currently
 * running./*  ww w  . j a v a 2  s.c  om*/
 *
 * @param context the Android context
 * @param activityClass the activity class to check
 * @return <tt>true</tt> if the activity given by the class is running,
 * <tt>false</tt> - otherwise
 */
public static boolean isActivityRunning(Context context, Class<?> activityClass) {
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

    List<ActivityManager.RunningTaskInfo> services = activityManager.getRunningTasks(Integer.MAX_VALUE);

    boolean isServiceFound = false;

    for (int i = 0; i < services.size(); i++) {
        if (services.get(i).topActivity.getClassName().equals(activityClass.getName())) {
            isServiceFound = true;
        }
    }
    return isServiceFound;
}

From source file:Main.java

/**
 * Check if the Jarvis services are running.
 * @param context - the context of the calling application.
 * @param serviceName - the name of the service.
 * @return <b>True</b> if the service is running,<br/><b>False</b> if the service is not running.
 * @author Vibhor// w ww  .  jav a  2  s  . c om
 */
public static boolean isIrisServiceRunning(Context context, String serviceName) {
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (serviceName.equals(service.service.getClassName())) {
            return true;
        }
    }
    return false;
}

From source file:com.enonic.esl.io.FileUtil.java

/**
 * Returns the contents of the file in a byte array.
 *
 * @param file the file info//  w w w . j  a  va  2 s  . c  o  m
 * @return a byte array containing the file's contents
 * @throws IOException
 */
public static byte[] getBytesFromFile(File file) throws IOException {
    InputStream is = new FileInputStream(file);

    // Get the size of the file
    long length = file.length();

    // 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 (length > Integer.MAX_VALUE) {
        // File is too large
    }

    // Create the byte array to hold the data
    byte[] bytes = new byte[(int) length];

    // Read in the bytes
    int offset = 0;
    int numRead = 0;
    while (offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
        offset += numRead;
    }

    // Ensure all the bytes have been read in
    if (offset < bytes.length) {
        throw new IOException("Could not completely read file " + file.getName());
    }

    // Close the input stream and return bytes
    is.close();
    return bytes;
}

From source file:Main.java

public static String getMd5Hash(File file) {
    try {//from  w w  w  .  ja va2 s. c  o  m
        // CTS (6/15/2010) : stream file through digest instead of handing it the byte[]
        MessageDigest md = MessageDigest.getInstance("MD5");
        int chunkSize = 256;

        byte[] chunk = new byte[chunkSize];

        // Get the size of the file
        long lLength = file.length();

        if (lLength > Integer.MAX_VALUE) {
            Log.e(t, "File " + file.getName() + "is too large");
            return null;
        }

        int length = (int) lLength;

        InputStream is = null;
        is = new FileInputStream(file);

        int l = 0;
        for (l = 0; l + chunkSize < length; l += chunkSize) {
            is.read(chunk, 0, chunkSize);
            md.update(chunk, 0, chunkSize);
        }

        int remaining = length - l;
        if (remaining > 0) {
            is.read(chunk, 0, remaining);
            md.update(chunk, 0, remaining);
        }
        byte[] messageDigest = md.digest();

        BigInteger number = new BigInteger(1, messageDigest);
        String md5 = number.toString(16);
        while (md5.length() < 32)
            md5 = "0" + md5;
        is.close();
        return md5;

    } catch (NoSuchAlgorithmException e) {
        Log.e("MD5", e.getMessage());
        return null;

    } catch (FileNotFoundException e) {
        Log.e("No Cache File", e.getMessage());
        return null;
    } catch (IOException e) {
        Log.e("Problem reading from file", e.getMessage());
        return null;
    }

}

From source file:com.linkedin.paldb.impl.GenerateTestData.java

public static Integer[] generateRandomIntKeys(int count, long seed) {
    return generateRandomIntKeys(count, Math.min(count * 50, Integer.MAX_VALUE), seed);
}