com.github.croesch.micro_debug.commons
Class Utils

java.lang.Object
  extended by com.github.croesch.micro_debug.commons.Utils

public final class Utils
extends Object

Class with utility methods.

Since:
Date: Nov 23, 2011
Author:
croesch

Method Summary
static int bytesToInt(byte b0, byte b1, byte b2, byte b3)
          Assembles the given bytes to one integer.
static void checkMagicNumber(InputStream in, int magic)
          Reads the first four bytes of the given InputStream and throws an exception if they aren't equal to the expected magic number.
static String getLineSeparator()
          Returns the line separator that is default for this system.
static int getNextHigherValue(int start, int... values)
          Giving a start value this iterates over all the other given values and returns the minimum of them that is higher than the given start value.
static boolean isOneValueMinusOne(int[] values)
          Returns whether one of the given numbers is equal to -1.
static void logThrownThrowable(Throwable t)
          Logs that the given Throwable has been thrown.
static String toHexString(int number)
          Returns a string representation of the integer argument as an unsigned integer in base 16.

For example: 100 → 0x64
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isOneValueMinusOne

public static boolean isOneValueMinusOne(int[] values)
Returns whether one of the given numbers is equal to -1.

Parameters:
values - the numbers to check if any is equal to -1.
Returns:
true, if at least one of the given values is equal to -1.
Since:
Date: Nov 13, 2011

checkMagicNumber

public static void checkMagicNumber(InputStream in,
                                    int magic)
                             throws FileFormatException,
                                    IllegalArgumentException
Reads the first four bytes of the given InputStream and throws an exception if they aren't equal to the expected magic number.

Parameters:
in - the stream to read the bytes from
magic - the magic number
Throws:
IllegalArgumentException - if the given stream is null.
FileFormatException - if:
  • the stream doesn't contain four bytes
  • the four bytes are not equal to the given magic number
  • an IOException occurs
Since:
Date: Nov 19, 2011

bytesToInt

public static int bytesToInt(byte b0,
                             byte b1,
                             byte b2,
                             byte b3)
Assembles the given bytes to one integer.

Parameters:
b0 - the most significant byte
b1 - the second most significant byte
b2 - the second least significant byte
b3 - the least significant byte
Returns:
an integer, assembled by the four bytes
Since:
Date: Nov 23, 2011

logThrownThrowable

public static void logThrownThrowable(Throwable t)
Logs that the given Throwable has been thrown.

Parameters:
t - the thrown Throwable to log
Since:
Date: Dec 2, 2011

toHexString

public static String toHexString(int number)
Returns a string representation of the integer argument as an unsigned integer in base 16.

For example: 100 → 0x64

Parameters:
number - the number to represent as hexadecimal string
Returns:
the string representation of the given number in upper case and with leading 0x
Since:
Date: Jan 14, 2012

getNextHigherValue

public static int getNextHigherValue(int start,
                                     int... values)
Giving a start value this iterates over all the other given values and returns the minimum of them that is higher than the given start value. So to say the next higher value seen from the starting point.

Parameters:
start - the number to start from
values - the other numbers to iterate over and to search for the next higher value
Returns:
the next higher value than the start number
or Integer.MAX_VALUE if no value is higher than the given start number.
Since:
Date: Jan 22, 2012

getLineSeparator

public static String getLineSeparator()
Returns the line separator that is default for this system.

Returns:
String that represents the line separator
Since:
Date: Jan 24, 2012


Copyright © 2012. All Rights Reserved.