deadbeef.Tools
Class ToolBox

java.lang.Object
  extended by deadbeef.Tools.ToolBox

public class ToolBox
extends java.lang.Object

Selection of utility functions.

Author:
0xdeadbeef

Constructor Summary
ToolBox()
           
 
Method Summary
static java.lang.String addSeparator(java.lang.String fName)
          Add (system default) path separator to string (if there isn't one already)
static java.lang.String exchangeSeparators(java.lang.String fName)
          Exchange any DOS style path separator ("\") with a Unix style separator ("/")
static java.lang.String formatDouble(double d)
          Format double as string in the form "xx.yyy"
static int getByte(byte[] buffer, int index)
          Read byte from a buffer from position index
static double getDouble(java.lang.String s)
          Convert String to double
static java.lang.String getExtension(java.lang.String path)
          Returns the extension (".XXX") of a filename without the dot
static byte[] getFileID(java.lang.String fname, int num)
          Returns the first few bytes of a file to check it's type
static java.lang.String getFileName(java.lang.String path)
          Return file name from path
static java.lang.String getFileName(java.lang.String path, java.lang.String fn, java.lang.String[] ext, boolean load, java.awt.Component parent)
          Get file name via "file chooser" dialog
static int getInt(java.lang.String s)
          Convert String to integer
static java.lang.String getPathName(java.lang.String path)
          Return path name from a file name
static int getWord(byte[] buffer, int index)
          Read (big endian) word from a buffer from position index
static java.lang.String hex(int val, int digits)
          Convert an integer to a C-style hex string with leading zeroes
static java.lang.String hex(long val, int digits)
          Convert a long integer to a C-style hex string with leading zeroes
static int[] msToTime(long ms)
          Convert time in milliseconds to array containing hours, minutes, seconds and milliseconds
static java.lang.String ptsToTimeStr(long pts)
          Convert time in 90kHz ticks to string hh:mm:ss.ms
static java.lang.String ptsToTimeStrIdx(long pts)
          Convert time in 90kHz ticks to string hh:mm:ss:ms
static java.lang.String ptsToTimeStrXml(long pts, double fps)
          Convert time in 90kHz ticks to string hh:mm:ss:ff (where ff is number of frames)
static void setByte(byte[] buffer, int index, int val)
          Write byte to buffer[index]
static void setDWord(byte[] buffer, int index, int val)
          Write (big endian) double word to buffer[index] (index points at most significant byte)
static void setString(byte[] buffer, int index, java.lang.String s)
          Write ASCII string to buffer[index] (no special handling for multi-byte characters)
static void setWord(byte[] buffer, int index, int val)
          Write (big endian) word to buffer[index] (index points at most significant byte)
static void showException(java.lang.Throwable ex)
          Show a dialog with details about an exception
static java.lang.String stripExtension(java.lang.String path)
          Strips the extension (".XXX") from a file name (including the dot) If no extension is found, the unchanged string is returned.
static long timeStrToPTS(java.lang.String s)
          Convert string in hh:mm:ss.ms or hh:mm:ss:ms format to time in 90kHz resolution
static long timeStrXmlToPTS(java.lang.String s, double fps)
          Convert string in hh:mm:ss:ff format to time in 90kHz resolution
static java.lang.String trim(java.lang.String s)
          Remove trailing and leading spaces from a string
static java.lang.String zeroTrim(int i, int digits)
          Convert an integer to a string with leading zeroes
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ToolBox

public ToolBox()
Method Detail

zeroTrim

public static java.lang.String zeroTrim(int i,
                                        int digits)
Convert an integer to a string with leading zeroes

Parameters:
i - Integer value to convert
digits - Number of digits to display (note: a 32bit number can have only 10 digits)
Returns:
String version of integer with trailing zeroes

hex

public static java.lang.String hex(long val,
                                   int digits)
Convert a long integer to a C-style hex string with leading zeroes

Parameters:
val - Integer value to convert
digits - Number of digits to display (note: a 32bit hex number can have only 8 digits)
Returns:
hex String version of integer with trailing zeroes (and starting with "0x")

hex

public static java.lang.String hex(int val,
                                   int digits)
Convert an integer to a C-style hex string with leading zeroes

Parameters:
val - Integer value to convert
digits - Number of digits to display (note: a 32bit hex number can have only 8 digits)
Returns:
hex String version of integer with trailing zeroes (and starting with "0x")

formatDouble

public static java.lang.String formatDouble(double d)
Format double as string in the form "xx.yyy"

Parameters:
d - Double value
Returns:
Formatted string

msToTime

public static int[] msToTime(long ms)
Convert time in milliseconds to array containing hours, minutes, seconds and milliseconds

Parameters:
ms - Time in milliseconds
Returns:
Array containing hours, minutes, seconds and milliseconds (in this order)

ptsToTimeStr

public static java.lang.String ptsToTimeStr(long pts)
Convert time in 90kHz ticks to string hh:mm:ss.ms

Parameters:
pts - Time in 90kHz resolution
Returns:
String in format hh:mm:ss:ms

ptsToTimeStrIdx

public static java.lang.String ptsToTimeStrIdx(long pts)
Convert time in 90kHz ticks to string hh:mm:ss:ms

Parameters:
pts - Time in 90kHz resolution
Returns:
String in format hh:mm:ss:ms

ptsToTimeStrXml

public static java.lang.String ptsToTimeStrXml(long pts,
                                               double fps)
Convert time in 90kHz ticks to string hh:mm:ss:ff (where ff is number of frames)

Parameters:
pts - Time in 90kHz resolution
fps - Frames per second
Returns:
String in format hh:mm:ss:ff

timeStrToPTS

public static long timeStrToPTS(java.lang.String s)
Convert string in hh:mm:ss.ms or hh:mm:ss:ms format to time in 90kHz resolution

Parameters:
s - String in hh:mm:ss.ms or hh:mm:ss:ms format
Returns:
Time in 90kHz resolution

timeStrXmlToPTS

public static long timeStrXmlToPTS(java.lang.String s,
                                   double fps)
Convert string in hh:mm:ss:ff format to time in 90kHz resolution

Parameters:
s - String in hh:mm:ss:ff format
fps - Frames per second
Returns:
Time in 90kHz resolution

getByte

public static int getByte(byte[] buffer,
                          int index)
                   throws java.lang.ArrayIndexOutOfBoundsException
Read byte from a buffer from position index

Parameters:
buffer - Byte array
index - Index to read from
Returns:
Integer value of byte buffer[index]
Throws:
java.lang.ArrayIndexOutOfBoundsException

getWord

public static int getWord(byte[] buffer,
                          int index)
                   throws java.lang.ArrayIndexOutOfBoundsException
Read (big endian) word from a buffer from position index

Parameters:
buffer - Byte array
index - Index to read from
Returns:
Integer value of word starting at buffer[index] (index points at most significant byte)
Throws:
java.lang.ArrayIndexOutOfBoundsException

setByte

public static void setByte(byte[] buffer,
                           int index,
                           int val)
                    throws java.lang.ArrayIndexOutOfBoundsException
Write byte to buffer[index]

Parameters:
buffer - Byte array
index - Index to write to
val - Integer value of byte to write
Throws:
java.lang.ArrayIndexOutOfBoundsException

setWord

public static void setWord(byte[] buffer,
                           int index,
                           int val)
                    throws java.lang.ArrayIndexOutOfBoundsException
Write (big endian) word to buffer[index] (index points at most significant byte)

Parameters:
buffer - Byte array
index - Index to write to
val - Integer value of word to write
Throws:
java.lang.ArrayIndexOutOfBoundsException

setDWord

public static void setDWord(byte[] buffer,
                            int index,
                            int val)
                     throws java.lang.ArrayIndexOutOfBoundsException
Write (big endian) double word to buffer[index] (index points at most significant byte)

Parameters:
buffer - Byte array
index - Index to write to
val - Integer value of double word to write
Throws:
java.lang.ArrayIndexOutOfBoundsException

setString

public static void setString(byte[] buffer,
                             int index,
                             java.lang.String s)
                      throws java.lang.ArrayIndexOutOfBoundsException
Write ASCII string to buffer[index] (no special handling for multi-byte characters)

Parameters:
buffer - Byte array
index - Index to write to
s - String containing ASCII characters
Throws:
java.lang.ArrayIndexOutOfBoundsException

showException

public static void showException(java.lang.Throwable ex)
Show a dialog with details about an exception

Parameters:
ex - Throwable/Exception to display

getFileName

public static java.lang.String getFileName(java.lang.String path,
                                           java.lang.String fn,
                                           java.lang.String[] ext,
                                           boolean load,
                                           java.awt.Component parent)
Get file name via "file chooser" dialog

Parameters:
path - Default path (without file name). Might be "", but not null.
fn - Default file name (without path). Can be null.
ext - Array of allowed extensions (without ".")
load - If true, this is a load dialog, else it's a save dialog
parent - Parent component (Frame, Window)
Returns:
Selected filename or null if canceled

addSeparator

public static java.lang.String addSeparator(java.lang.String fName)
Add (system default) path separator to string (if there isn't one already)

Parameters:
fName - String containing path name
Returns:
String that ends with the (system default) path separator for sure

exchangeSeparators

public static java.lang.String exchangeSeparators(java.lang.String fName)
Exchange any DOS style path separator ("\") with a Unix style separator ("/")

Parameters:
fName - String containing file/path name
Returns:
String with only Unix style path separators

getFileName

public static java.lang.String getFileName(java.lang.String path)
Return file name from path

Parameters:
path - String of a path with a file name
Returns:
String containing only the file name

getPathName

public static java.lang.String getPathName(java.lang.String path)
Return path name from a file name

Parameters:
path - String of file name with a path
Returns:
String containing only the path (excluding path separator)

getExtension

public static java.lang.String getExtension(java.lang.String path)
Returns the extension (".XXX") of a filename without the dot

Parameters:
path - String containing file name
Returns:
String containing only the extension (without the dot) or null (if no extension found)

stripExtension

public static java.lang.String stripExtension(java.lang.String path)
Strips the extension (".XXX") from a file name (including the dot) If no extension is found, the unchanged string is returned.

Parameters:
path - String containing a file name
Returns:
String to a filename without the extension

getFileID

public static byte[] getFileID(java.lang.String fname,
                               int num)
Returns the first few bytes of a file to check it's type

Parameters:
fname - Filename of the file
num - Number of bytes to return
Returns:
Array of bytes (size num) from the beginning of the file

trim

public static java.lang.String trim(java.lang.String s)
Remove trailing and leading spaces from a string

Parameters:
s - String to process
Returns:
String without leading and trailing spaces

getInt

public static int getInt(java.lang.String s)
Convert String to integer

Parameters:
s - String containing integer (assumed: positive)
Returns:
Integer value or -1.0 if no valid numerical value

getDouble

public static double getDouble(java.lang.String s)
Convert String to double

Parameters:
s - String containing double
Returns:
Double value or -1.0 if no valid numerical value