org.freecompany.redline
Class Util

java.lang.Object
  extended by org.freecompany.redline.Util

public class Util
extends Object

General utilities needed to read and write RPM files. Some of these utilities are available elsewhere but reproduced here to minimize runtime dependencies.


Method Summary
static void check(byte expected, byte actual)
          Checks that two bytes are the same, while generating a formatted error message if they are not.
static void check(int expected, int actual)
          Checks that two integers are the same, while generating a formatted error message if they are not.
static int difference(int start, int boundary)
           
static void dump(byte[] data)
           
static void dump(byte[] data, Appendable out)
           
static void dump(ByteBuffer buf, Appendable out)
           
static void dump(char[] data)
           
static void dump(char[] data, Appendable out)
           
static void dump(CharSequence data)
           
static void empty(WritableByteChannel out, ByteBuffer buffer)
          Empties the contents of the given buffer into the writable channel provided.
static ByteBuffer fill(ReadableByteChannel in, ByteBuffer buffer)
          Fills the provided buffer it with bytes from the provided channel.
static ByteBuffer fill(ReadableByteChannel in, int size)
          Creates a new buffer and fills it with bytes from the provided channel.
static String hex(byte[] data)
           
static String normalizePath(String path)
          Converts path characters from their native format to the "forward-slash" format expected within RPM files.
static void pad(ByteBuffer buffer, int boundary)
          Pads the given buffer up to the indicated boundary.
static int round(int start, int boundary)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

normalizePath

public static String normalizePath(String path)
Converts path characters from their native format to the "forward-slash" format expected within RPM files.


fill

public static ByteBuffer fill(ReadableByteChannel in,
                              int size)
                       throws IOException
Creates a new buffer and fills it with bytes from the provided channel. The amount of data to read is specified in the arguments.

Parameters:
in - the channel to read from
size - the number of bytes to read into a new buffer
Returns:
a new buffer containing the bytes read
Throws:
IOException - if an IO error occurs

fill

public static ByteBuffer fill(ReadableByteChannel in,
                              ByteBuffer buffer)
                       throws IOException
Fills the provided buffer it with bytes from the provided channel. The amount of data to read is dependant on the available space in the provided buffer.

Parameters:
in - the channel to read from
buffer - the buffer to read into
Returns:
the provided buffer
Throws:
IOException - if an IO error occurs

empty

public static void empty(WritableByteChannel out,
                         ByteBuffer buffer)
                  throws IOException
Empties the contents of the given buffer into the writable channel provided. The buffer will be copied to the channel in it's entirety.

Parameters:
out - the channel to write to
buffer - the buffer to write out to the channel
Throws:
IOException - if an IO error occurs

check

public static void check(int expected,
                         int actual)
                  throws IOException
Checks that two integers are the same, while generating a formatted error message if they are not. The error message will indicate the hex value of the integers if they do not match.

Parameters:
expected - the expected value
actual - the actual value
Throws:
IOException - if the two values do not match

check

public static void check(byte expected,
                         byte actual)
                  throws IOException
Checks that two bytes are the same, while generating a formatted error message if they are not. The error message will indicate the hex value of the bytes if they do not match.

Parameters:
expected - the expected value
actual - the actual value
Throws:
IOException - if the two values do not match

difference

public static int difference(int start,
                             int boundary)

round

public static int round(int start,
                        int boundary)

pad

public static void pad(ByteBuffer buffer,
                       int boundary)
Pads the given buffer up to the indicated boundary. The RPM file format requires that headers be aligned with various boundaries, this method pads output to match the requirements.

Parameters:
buffer - the buffer to pad zeros into
boundary - the boundary to which we need to pad

dump

public static void dump(byte[] data)

dump

public static void dump(byte[] data,
                        Appendable out)

dump

public static void dump(char[] data)

dump

public static void dump(CharSequence data)

dump

public static void dump(char[] data,
                        Appendable out)

dump

public static void dump(ByteBuffer buf,
                        Appendable out)

hex

public static String hex(byte[] data)


Copyright © 2012. All Rights Reserved.