private String getFileContents(String file) throws IOException { InputStream in = this.getClass().getClassLoader().getResourceAsStream(file); Reader reader = new InputStreamReader(in); String webXML = ObjectConverterUtil.convertToString(reader); return webXML; }
/** * 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. */ public static byte[] convertToByteArray(final InputStream is, int length) throws IOException { return convertToByteArray(is, length, true); }
public static int write(final OutputStream out, final InputStream is, byte[] l_buffer, int length) throws IOException { return write(out, is, l_buffer, length, true, true); }
public static void write(char[] data, final String fileName) throws Exception { InputStream is = ObjectConverterUtil.convertToInputStream(data); ObjectConverterUtil.write(is, fileName); is.close(); }
public static byte[] convertToByteArray(final Object data) throws TeiidException, IOException { if (data instanceof InputStream) { return convertToByteArray((InputStream) data); } else if (data instanceof byte[]) { return (byte[]) data; } else if (data instanceof java.sql.Blob) { return convertBlobToByteArray((java.sql.Blob) data); } else if (data instanceof File) { return convertFileToByteArray((File)data); } final Object[] params = new Object[]{data.getClass().getName()}; throw new TeiidException(CorePlugin.Event.TEIID10032, CorePlugin.Util.gs(CorePlugin.Event.TEIID10032,params)); }
} else if (value instanceof BlobType) { json.writeString(Base64.encodeBytes( ObjectConverterUtil.convertToByteArray(((Blob) value).getBinaryStream()))); } else if (value instanceof SQLXML) { json.writeString(ObjectConverterUtil.convertToString(((SQLXML) value).getCharacterStream())); } else if (value instanceof byte[] ) { json.writeString(Base64.encodeBytes((byte[])value));
/** * Returns the given bytes as a char array using a given encoding (null means platform default). */ public static char[] bytesToChar(byte[] bytes, String encoding) throws IOException { return convertToCharArray(new ByteArrayInputStream(bytes), bytes.length, encoding); } /**
File manifest = new File(dir, "MetaMatrix-VdbManifestModel.xmi"); if (manifest.exists()) { String configStr = ObjectConverterUtil.convertFileToString(config); String manifestStr = ObjectConverterUtil.convertFileToString(manifest); int index = configStr.lastIndexOf("</VDB>"); int manifestBegin = manifestStr.indexOf("<xmi");
} else if (value instanceof BlobType) { json.writeStringField(key, Base64.encodeBytes( ObjectConverterUtil.convertToByteArray(((Blob) value).getBinaryStream()))); } else if (value instanceof SQLXML) { json.writeStringField(key, ObjectConverterUtil.convertToString(((SQLXML) value).getCharacterStream())); } else if (value instanceof byte[] ) { json.writeStringField(key, Base64.encodeBytes((byte[])value));
public static void write(byte[] data, final String fileName) throws Exception { InputStream is = ObjectConverterUtil.convertToInputStream(data); ObjectConverterUtil.write(is, fileName); is.close(); }
public static byte[] convertToByteArray(final Object data) throws TeiidException, IOException { if (data instanceof InputStream) { return convertToByteArray((InputStream) data); } else if (data instanceof byte[]) { return (byte[]) data; } else if (data instanceof java.sql.Blob) { return convertBlobToByteArray((java.sql.Blob) data); } else if (data instanceof File) { return convertFileToByteArray((File)data); } final Object[] params = new Object[]{data.getClass().getName()}; throw new TeiidException(CorePlugin.Event.TEIID10032, CorePlugin.Util.gs(CorePlugin.Event.TEIID10032,params)); }
/** * Returns the contents of the given InputStream as a string. * @throws IOException if a problem occurred reading the file. */ public static String convertToString(final InputStream stream) throws IOException { return new String(convertToCharArray(stream, -1, "UTF-8")); //$NON-NLS-1$ }
public String getContentOfTestFile( final String testFilePath ) throws IOException { final File file = UnitTestUtil.getTestDataFile(testFilePath); return ObjectConverterUtil.convertFileToString(file); }
private String getFileContents(String file) throws IOException { InputStream in = this.getClass().getClassLoader().getResourceAsStream(file); Reader reader = new InputStreamReader(in); String webXML = ObjectConverterUtil.convertToString(reader); return webXML; }
/** * 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. */ public static byte[] convertToByteArray(final InputStream is, int length) throws IOException { return convertToByteArray(is, length, true); }
public static int write(final OutputStream out, final InputStream is, int length) throws IOException { return write(out, is, length, true); }
public static void write(byte[] data, final String fileName) throws Exception { InputStream is = ObjectConverterUtil.convertToInputStream(data); ObjectConverterUtil.write(is, fileName); is.close(); }
/** * Returns the given bytes as a char array using a given encoding (null means platform default). */ public static char[] bytesToChar(byte[] bytes, String encoding) throws IOException { return convertToCharArray(new ByteArrayInputStream(bytes), bytes.length, encoding); } /**
/** * Tests FileUtils.copy() * @since 4.3 */ public void testCopy() throws Exception { String contents1 = ObjectConverterUtil.convertFileToString(new File(FILE_NAME)); //positive case FileUtils.copy(FILE_NAME, TEMP_FILE_NAME, false); String contents2 = ObjectConverterUtil.convertFileToString(new File(TEMP_FILE_NAME)); assertEquals("Expected file contents to be the same", contents1, contents2); //$NON-NLS-1$ assertTrue("Expected original file to still exist", new File(FILE_NAME).exists()); //$NON-NLS-1$ //negative case: should fail because file already exists try { FileUtils.copy(FILE_NAME, TEMP_FILE_NAME, false); fail("Expected MetaMatrixException"); //$NON-NLS-1$ } catch (IOException e) { } //positive case: should succeed because we've specified to overwrite FileUtils.copy(FILE_NAME, TEMP_FILE_NAME, true); contents2 = ObjectConverterUtil.convertFileToString(new File(TEMP_FILE_NAME)); assertEquals("Expected file contents to be the same", contents1, contents2); //$NON-NLS-1$ assertTrue("Expected original file to still exist", new File(FILE_NAME).exists()); //$NON-NLS-1$ }
public String getString() throws SQLException { try { return ObjectConverterUtil.convertToString(getCharacterStream()); } catch (IOException e) { SQLException ex = new SQLException(e.getMessage()); ex.initCause(e); throw ex; } }