Package org.teiid.core.util
Class ObjectConverterUtil
- java.lang.Object
-
- org.teiid.core.util.ObjectConverterUtil
-
public class ObjectConverterUtil extends Object
-
-
Constructor Summary
Constructors Constructor Description ObjectConverterUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static char[]
bytesToChar(byte[] bytes, String encoding)
Returns the given bytes as a char array using a given encoding (null means platform default).protected static byte[]
convertBlobToByteArray(Blob data)
static byte[]
convertFileToByteArray(File file)
Returns the contents of the given file as a byte array.static String
convertFileToString(File file)
Returns the contents of the given file as a string.static byte[]
convertToByteArray(InputStream is)
static byte[]
convertToByteArray(InputStream is, int length)
Returns the given input stream's contents as a byte array.static byte[]
convertToByteArray(InputStream is, int length, boolean close)
static byte[]
convertToByteArray(Object data)
static byte[]
convertToByteArray(ZipEntry ze, ZipFile zip)
Returns the contents of the given zip entry as a byte array.static char[]
convertToCharArray(InputStream stream, int length, String encoding)
Returns the given input stream's contents as a character array.static InputStream
convertToInputStream(byte[] data)
static String
convertToString(InputStream stream)
Returns the contents of the given InputStream as a string.static String
convertToString(Reader reader)
static String
convertToString(Reader reader, int length)
static void
write(byte[] data, String fileName)
static void
write(InputStream is, File f)
static void
write(InputStream is, String fileName)
static int
write(OutputStream out, InputStream is, byte[] l_buffer, int length)
static int
write(OutputStream out, InputStream is, byte[] l_buffer, int length, boolean closeBoth)
static int
write(OutputStream out, InputStream is, byte[] l_buffer, int length, boolean closeOutput, boolean closeInput)
static int
write(OutputStream out, InputStream is, int length)
static int
write(OutputStream out, InputStream is, int length, boolean close)
static int
write(OutputStream out, InputStream is, int length, boolean closeOutput, boolean closeInput)
static int
write(Writer out, Reader is, int length, boolean close)
-
-
-
Method Detail
-
convertBlobToByteArray
protected static byte[] convertBlobToByteArray(Blob data) throws TeiidException
- Throws:
TeiidException
-
convertToByteArray
public static byte[] convertToByteArray(Object data) throws TeiidException, IOException
- Throws:
TeiidException
IOException
-
convertToByteArray
public static byte[] convertToByteArray(InputStream is) throws IOException
- Throws:
IOException
-
convertToByteArray
public static byte[] convertToByteArray(InputStream is, int length) throws IOException
Returns the given input stream's contents as a byte array. If a length is specified (ie. if length != -1), only length bytes are returned. Otherwise all bytes in the stream are returned. Note this does close the stream, even if not all bytes are written, because the buffering does not guarantee the end position.- Throws:
IOException
- if a problem occurred reading the stream.
-
convertToByteArray
public static byte[] convertToByteArray(InputStream is, int length, boolean close) throws IOException
- Throws:
IOException
-
write
public static int write(OutputStream out, InputStream is, byte[] l_buffer, int length) throws IOException
- Throws:
IOException
-
write
public static int write(OutputStream out, InputStream is, byte[] l_buffer, int length, boolean closeBoth) throws IOException
- Throws:
IOException
-
write
public static int write(OutputStream out, InputStream is, byte[] l_buffer, int length, boolean closeOutput, boolean closeInput) throws IOException
- Throws:
IOException
-
write
public static int write(OutputStream out, InputStream is, int length) throws IOException
- Throws:
IOException
-
write
public static int write(OutputStream out, InputStream is, int length, boolean close) throws IOException
- Throws:
IOException
-
write
public static int write(OutputStream out, InputStream is, int length, boolean closeOutput, boolean closeInput) throws IOException
- Throws:
IOException
-
write
public static int write(Writer out, Reader is, int length, boolean close) throws IOException
- Throws:
IOException
-
convertToInputStream
public static InputStream convertToInputStream(byte[] data)
-
write
public static void write(InputStream is, String fileName) throws IOException
- Throws:
IOException
-
write
public static void write(InputStream is, File f) throws IOException
- Throws:
IOException
-
bytesToChar
public static char[] bytesToChar(byte[] bytes, String encoding) throws IOException
Returns the given bytes as a char array using a given encoding (null means platform default).- Throws:
IOException
-
convertFileToByteArray
public static byte[] convertFileToByteArray(File file) throws IOException
Returns the contents of the given file as a byte array.- Throws:
IOException
- if a problem occurred reading the file.
-
convertFileToString
public static String convertFileToString(File file) throws IOException
Returns the contents of the given file as a string.- Throws:
IOException
- if a problem occurred reading the file.
-
convertToString
public static String convertToString(InputStream stream) throws IOException
Returns the contents of the given InputStream as a string.- Throws:
IOException
- if a problem occurred reading the file.
-
convertToCharArray
public static char[] convertToCharArray(InputStream stream, int length, String encoding) throws IOException
Returns the given input stream's contents as a character array. If a length is specified (ie. if length != -1), only length chars are returned. Otherwise all chars in the stream are returned. Note this doesn't close the stream.- Throws:
IOException
- if a problem occurred reading the stream.
-
convertToByteArray
public static byte[] convertToByteArray(ZipEntry ze, ZipFile zip) throws IOException
Returns the contents of the given zip entry as a byte array.- Throws:
IOException
- if a problem occurred reading the zip entry.
-
convertToString
public static String convertToString(Reader reader) throws IOException
- Throws:
IOException
-
convertToString
public static String convertToString(Reader reader, int length) throws IOException
- Throws:
IOException
-
-