uk.me.parabola.imgfmt
Class Utils

java.lang.Object
  extended by uk.me.parabola.imgfmt.Utils

public class Utils
extends java.lang.Object

Some miscellaneous functions that are used within the .img code.

Author:
Steve Ratcliffe

Constructor Summary
Utils()
           
 
Method Summary
static java.lang.String bytesToString(java.nio.ByteBuffer buf, int off, int len)
          Convert from bytes to a string.
static void closeFile(java.io.Closeable f)
           
static java.lang.String joinPath(java.lang.String dir, java.lang.String basename)
           
static java.lang.String joinPath(java.lang.String dir, java.lang.String basename, java.lang.String ext)
           
static java.util.Date makeCreationTime(byte[] date)
          Make a date from the garmin representation.
static byte[] makeCreationTime(java.util.Date date)
          Convert a date into the in-file representation of a date.
static java.io.InputStream openFile(java.lang.String name)
          Open a file and apply filters necessary for reading it such as decompression.
static void setCreationTime(java.nio.ByteBuffer buf, java.util.Date date)
          Set the creation date.
static byte[] toBytes(java.lang.String s)
           
static byte[] toBytes(java.lang.String s, int len, byte pad)
          Routine to convert a string to bytes and pad with a character up to a given length.
static double toDegrees(int val)
          Convert an angle in map units to degrees.
static int toMapUnit(double l)
          A map unit is an integer value that is 1/(2^24) degrees of latitude or longitude.
static double toRadians(int mapunits)
          Convert an angle in map units to radians.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Utils

public Utils()
Method Detail

toBytes

public static byte[] toBytes(java.lang.String s,
                             int len,
                             byte pad)
Routine to convert a string to bytes and pad with a character up to a given length. Only to be used for strings that are expressible in latin1.

Parameters:
s - The original string.
len - The length to pad to.
pad - The byte used to pad.
Returns:
An array created from the string.

toBytes

public static byte[] toBytes(java.lang.String s)

bytesToString

public static java.lang.String bytesToString(java.nio.ByteBuffer buf,
                                             int off,
                                             int len)
Convert from bytes to a string. Only to be used when the character set is ascii or latin1.

Parameters:
buf - A byte buffer to get the bytes from. Should be ascii or latin1.
off - The offset into buf.
len - The length to get.
Returns:
A string.

setCreationTime

public static void setCreationTime(java.nio.ByteBuffer buf,
                                   java.util.Date date)
Set the creation date. Note that the year is encoded specially.

Parameters:
buf - The buffer to write into. It must have been properly positioned beforehand.
date - The date to set.

toMapUnit

public static int toMapUnit(double l)
A map unit is an integer value that is 1/(2^24) degrees of latitude or longitude.

Parameters:
l - The lat or long as decimal degrees.
Returns:
An integer value in map units.

makeCreationTime

public static byte[] makeCreationTime(java.util.Date date)
Convert a date into the in-file representation of a date.

Parameters:
date - The date.
Returns:
A byte stream in .img format.

makeCreationTime

public static java.util.Date makeCreationTime(byte[] date)
Make a date from the garmin representation.

Parameters:
date - The bytes representing the date.
Returns:
A java date.

toDegrees

public static double toDegrees(int val)
Convert an angle in map units to degrees.


toRadians

public static double toRadians(int mapunits)
Convert an angle in map units to radians.


closeFile

public static void closeFile(java.io.Closeable f)

openFile

public static java.io.InputStream openFile(java.lang.String name)
                                    throws java.io.FileNotFoundException
Open a file and apply filters necessary for reading it such as decompression.

Parameters:
name - The file to open.
Returns:
A stream that will read the file, positioned at the beginning.
Throws:
java.io.FileNotFoundException - If the file cannot be opened for any reason.

joinPath

public static java.lang.String joinPath(java.lang.String dir,
                                        java.lang.String basename,
                                        java.lang.String ext)

joinPath

public static java.lang.String joinPath(java.lang.String dir,
                                        java.lang.String basename)