public class Utils extends Object
| Modifier and Type | Method and Description |
|---|---|
static StringBuilder |
append(StringBuilder sb,
byte b)
Appends the hex string representing the given byte value to a StringBuffer.
|
static StringBuilder |
append(StringBuilder sb,
byte[] bytes,
int offset,
int length)
Appends the hex string representing the given byte values to a StringBuffer.
|
static InputStream |
getInputStream(String filename)
Returns an input stream for reading the content of a file or resource.
|
static byte[] |
readBytes(InputStream in)
Reads the entire contents of the given stream into a byte array.
|
static String[] |
readLines(File file)
Reads an entire text file into an array of lines.
|
static String[] |
readLines(InputStream in)
Reads an entire text stream into an array of lines.
|
static long |
readVarint(InputStream in)
Reads a varint (variable-length integer) from a stream.
|
static void |
writeVarint(OutputStream out,
long val)
Writes a varint (variable-length integer) to a stream.
|
public static InputStream getInputStream(String filename) throws FileNotFoundException
First an attempt is made to read from a file with the given name (full path).
If such a file does not exist, an attempt is made to load a resource with
the same name preceded by a slash using Class.getResourceAsStream(java.lang.String).
filename - the file (or resource) name.FileNotFoundException - if a file or resource with the given name
is not foundpublic static byte[] readBytes(InputStream in) throws IOException
in - an input streamIOException - if an error occurspublic static String[] readLines(File file) throws IOException
file - the file to readIOException - if an error occurspublic static String[] readLines(InputStream in) throws IOException
in - the steam to read fromIOException - if an error occurspublic static long readVarint(InputStream in) throws IOException
in - the stream to read fromIOException - if an error occurspublic static void writeVarint(OutputStream out, long val) throws IOException
out - the stream to write toval - the value to writeIOException - if an error occurspublic static StringBuilder append(StringBuilder sb, byte b)
sb - the StringBuffer to append tob - the byte value whose hex string representation is to be appendedpublic static StringBuilder append(StringBuilder sb, byte[] bytes, int offset, int length)
sb - the StringBuffer to append tobytes - the byte values whose hex string representation is to be appendedoffset - the offset within the byte array where the values startlength - the number of valuesCopyright © 2017 freeutils.net. All rights reserved.