org.teiid.core.util
Class ObjectConverterUtil

java.lang.Object
  extended by org.teiid.core.util.ObjectConverterUtil

public class ObjectConverterUtil
extends java.lang.Object


Constructor Summary
ObjectConverterUtil()
           
 
Method Summary
static char[] bytesToChar(byte[] bytes, java.lang.String encoding)
          Returns the given bytes as a char array using a given encoding (null means platform default).
protected static byte[] convertBlobToByteArray(java.sql.Blob data)
           
static byte[] convertFileToByteArray(java.io.File file)
          Returns the contents of the given file as a byte array.
static char[] convertFileToCharArray(java.io.File file, java.lang.String encoding)
          Returns the contents of the given file as a char array.
static java.lang.String convertFileToString(java.io.File file)
          Returns the contents of the given file as a string.
static byte[] convertToByteArray(java.io.InputStream is)
           
static byte[] convertToByteArray(java.io.InputStream is, int length)
          Returns the given input stream's contents as a byte array.
static byte[] convertToByteArray(java.io.InputStream is, int length, boolean close)
           
static byte[] convertToByteArray(java.lang.Object data)
           
static byte[] convertToByteArray(java.util.zip.ZipEntry ze, java.util.zip.ZipFile zip)
          Returns the contents of the given zip entry as a byte array.
static char[] convertToCharArray(java.io.InputStream stream, int length, java.lang.String encoding)
          Returns the given input stream's contents as a character array.
static char[] convertToCharArray(java.io.Reader reader, int length)
           
static java.io.InputStream convertToInputStream(byte[] data)
           
static java.io.InputStream convertToInputStream(char[] data)
           
static java.io.InputStream convertToInputStream(java.lang.String data)
           
static java.lang.String convertToString(java.io.InputStream stream)
          Returns the contents of the given InputStream as a string.
static java.lang.String convertToString(java.io.Reader reader)
           
static void write(byte[] data, java.lang.String fileName)
           
static void write(char[] data, java.lang.String fileName)
           
static void write(java.io.InputStream is, java.io.File f)
           
static void write(java.io.InputStream is, java.lang.String fileName)
           
static int write(java.io.OutputStream out, java.io.InputStream is, byte[] l_buffer, int length)
           
static int write(java.io.OutputStream out, java.io.InputStream is, byte[] l_buffer, int length, boolean close)
           
static int write(java.io.OutputStream out, java.io.InputStream is, int length)
           
static int write(java.io.OutputStream out, java.io.InputStream is, int length, boolean close)
           
static void write(java.io.Reader reader, java.io.File f)
           
static void write(java.io.Reader reader, java.lang.String fileName)
           
static int write(java.io.Writer out, java.io.Reader is, int length, boolean close)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectConverterUtil

public ObjectConverterUtil()
Method Detail

convertBlobToByteArray

protected static byte[] convertBlobToByteArray(java.sql.Blob data)
                                        throws TeiidException
Throws:
TeiidException

convertToByteArray

public static byte[] convertToByteArray(java.lang.Object data)
                                 throws TeiidException,
                                        java.io.IOException
Throws:
TeiidException
java.io.IOException

convertToByteArray

public static byte[] convertToByteArray(java.io.InputStream is)
                                 throws java.io.IOException
Throws:
java.io.IOException

convertToByteArray

public static byte[] convertToByteArray(java.io.InputStream is,
                                        int length)
                                 throws java.io.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:
java.io.IOException - if a problem occurred reading the stream.

convertToByteArray

public static byte[] convertToByteArray(java.io.InputStream is,
                                        int length,
                                        boolean close)
                                 throws java.io.IOException
Throws:
java.io.IOException

write

public static int write(java.io.OutputStream out,
                        java.io.InputStream is,
                        byte[] l_buffer,
                        int length)
                 throws java.io.IOException
Throws:
java.io.IOException

write

public static int write(java.io.OutputStream out,
                        java.io.InputStream is,
                        byte[] l_buffer,
                        int length,
                        boolean close)
                 throws java.io.IOException
Throws:
java.io.IOException

write

public static int write(java.io.OutputStream out,
                        java.io.InputStream is,
                        int length)
                 throws java.io.IOException
Throws:
java.io.IOException

write

public static int write(java.io.OutputStream out,
                        java.io.InputStream is,
                        int length,
                        boolean close)
                 throws java.io.IOException
Throws:
java.io.IOException

write

public static int write(java.io.Writer out,
                        java.io.Reader is,
                        int length,
                        boolean close)
                 throws java.io.IOException
Throws:
java.io.IOException

convertToInputStream

public static java.io.InputStream convertToInputStream(byte[] data)

convertToInputStream

public static java.io.InputStream convertToInputStream(java.lang.String data)

convertToInputStream

public static java.io.InputStream convertToInputStream(char[] data)

write

public static void write(java.io.InputStream is,
                         java.lang.String fileName)
                  throws java.io.IOException
Throws:
java.io.IOException

write

public static void write(java.io.Reader reader,
                         java.lang.String fileName)
                  throws java.io.IOException
Throws:
java.io.IOException

write

public static void write(java.io.Reader reader,
                         java.io.File f)
                  throws java.io.IOException
Throws:
java.io.IOException

write

public static void write(java.io.InputStream is,
                         java.io.File f)
                  throws java.io.IOException
Throws:
java.io.IOException

write

public static void write(byte[] data,
                         java.lang.String fileName)
                  throws java.lang.Exception
Throws:
java.lang.Exception

write

public static void write(char[] data,
                         java.lang.String fileName)
                  throws java.lang.Exception
Throws:
java.lang.Exception

bytesToChar

public static char[] bytesToChar(byte[] bytes,
                                 java.lang.String encoding)
                          throws java.io.IOException
Returns the given bytes as a char array using a given encoding (null means platform default).

Throws:
java.io.IOException

convertFileToByteArray

public static byte[] convertFileToByteArray(java.io.File file)
                                     throws java.io.IOException
Returns the contents of the given file as a byte array.

Throws:
java.io.IOException - if a problem occurred reading the file.

convertFileToCharArray

public static char[] convertFileToCharArray(java.io.File file,
                                            java.lang.String encoding)
                                     throws java.io.IOException
Returns the contents of the given file as a char array. When encoding is null, then the platform default one is used

Throws:
java.io.IOException - if a problem occurred reading the file.

convertFileToString

public static java.lang.String convertFileToString(java.io.File file)
                                            throws java.io.IOException
Returns the contents of the given file as a string.

Throws:
java.io.IOException - if a problem occurred reading the file.

convertToString

public static java.lang.String convertToString(java.io.InputStream stream)
                                        throws java.io.IOException
Returns the contents of the given InputStream as a string.

Throws:
java.io.IOException - if a problem occurred reading the file.

convertToCharArray

public static char[] convertToCharArray(java.io.InputStream stream,
                                        int length,
                                        java.lang.String encoding)
                                 throws java.io.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:
java.io.IOException - if a problem occurred reading the stream.

convertToByteArray

public static byte[] convertToByteArray(java.util.zip.ZipEntry ze,
                                        java.util.zip.ZipFile zip)
                                 throws java.io.IOException
Returns the contents of the given zip entry as a byte array.

Throws:
java.io.IOException - if a problem occurred reading the zip entry.

convertToString

public static java.lang.String convertToString(java.io.Reader reader)
                                        throws java.io.IOException
Throws:
java.io.IOException

convertToCharArray

public static char[] convertToCharArray(java.io.Reader reader,
                                        int length)
                                 throws java.io.IOException
Throws:
java.io.IOException


Copyright © 2011. All Rights Reserved.