List of usage examples for java.io FileOutputStream write
public void write(byte b[]) throws IOException
b.length
bytes from the specified byte array to this file output stream. From source file:com.autentia.wuija.reports.JasperReportsHelper.java
public static File writeExportedReportToFile(String fileName, Format format, final ByteArrayOutputStream output) { File file;//from w ww . ja va2 s . c om FileOutputStream fos = null; try { file = File.createTempFile(fileName, "." + format.toString().toLowerCase()); fos = new FileOutputStream(file); fos.write(output.toByteArray()); fos.flush(); } catch (IOException e) { final String msg = "Exception writing the report generated."; log.error(msg, e); throw new JRRuntimeException(msg, e); } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { log.warn("Cannot close file of generated report", e); } } } return file; }
From source file:jmupen.JMupenUpdater.java
/** * Writes the given bytes (within the specified range) to the given file. * * @param aFile File where bytes will be written to * @param theBytes The bytes to write/* ww w. j ava 2 s. c o m*/ * @throws java.io.IOException */ public static void writeBytes(File aFile, byte theBytes[]) throws IOException { if (theBytes == null) { aFile.delete(); return; } FileOutputStream fileStream = new FileOutputStream(aFile); fileStream.write(theBytes); fileStream.close(); }
From source file:com.netflix.niws.client.http.SecureAcceptAllGetTest.java
@BeforeClass public static void init() throws Exception { // setup server 1, will use first keystore/truststore with client auth TEST_PORT = new Random().nextInt(1000) + 4000; TEST_SERVICE_URI = "https://127.0.0.1:" + TEST_PORT + "/"; // jks format byte[] sampleTruststore1 = Base64.decode(SecureGetTest.TEST_TS1); byte[] sampleKeystore1 = Base64.decode(SecureGetTest.TEST_KS1); TEST_FILE_KS = File.createTempFile("SecureAcceptAllGetTest", ".keystore"); TEST_FILE_TS = File.createTempFile("SecureAcceptAllGetTest", ".truststore"); FileOutputStream keystoreFileOut = new FileOutputStream(TEST_FILE_KS); try {/*from w w w . j a v a2 s.c o m*/ keystoreFileOut.write(sampleKeystore1); } finally { keystoreFileOut.close(); } FileOutputStream truststoreFileOut = new FileOutputStream(TEST_FILE_TS); try { truststoreFileOut.write(sampleTruststore1); } finally { truststoreFileOut.close(); } try { TEST_SERVER = new SimpleSSLTestServer(TEST_FILE_TS, SecureGetTest.PASSWORD, TEST_FILE_KS, SecureGetTest.PASSWORD, TEST_PORT, false); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
From source file:kilim.tools.Weaver.java
static void writeClass(ClassInfo ci) throws IOException { String className = ci.className.replace('.', File.separatorChar); String dir = outputDir + File.separatorChar + getDirName(className); mkdir(dir);//from www . ja v a 2 s .co m // Convert name to fully qualified file name className = outputDir + File.separatorChar + className + ".class"; if (ci.className.startsWith("kilim.S_")) { // Check if we already have that file if (new File(className).exists()) return; } FileOutputStream fos = new FileOutputStream(className); fos.write(ci.bytes); fos.close(); if (verbose) { log.info("Wrote: " + className); } }
From source file:be.fedict.eidviewer.lib.X509Utilities.java
public static void certificateToDERFile(X509Certificate certificate, File file) throws CertificateEncodingException, IOException { FileOutputStream outputStream = null; try {//from w ww . java2 s . c o m outputStream = new FileOutputStream(file); outputStream.write(certificate.getEncoded()); } finally { if (outputStream != null) outputStream.close(); } }
From source file:org.pmedv.core.util.ResourceUtils.java
/** * Writes a given <code>InputStream</code> to a file. * //from w w w .jav a 2 s . com * @param is * @param out */ public static void writeStreamToFile(InputStream is, File out) { byte[] b; try { FileOutputStream fos = new FileOutputStream(out); b = new byte[is.available()]; for (int n; (n = is.read(b)) != -1;) { fos.write(b); } fos.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static void copyAsset(Context context, String assetFileName, String dstFile) { AssetManager assetManager = null;// w w w. j a v a 2s. c om assetManager = context.getAssets(); InputStream inputStream = null; FileOutputStream fileOutputStream = null; try { inputStream = assetManager.open(assetFileName); fileOutputStream = new FileOutputStream(dstFile); byte[] buffer = new byte[inputStream.available()]; inputStream.read(buffer); fileOutputStream.write(buffer); fileOutputStream.flush(); } catch (Exception ex) { ex.printStackTrace(); } finally { try { inputStream.close(); fileOutputStream.close(); } catch (Exception ex) { ex.printStackTrace(); } } }
From source file:com.znsx.util.licence.LicenceUtil.java
/** * ?DSA??p,q,g,j,x,y/*from w w w . ja va 2s. co m*/ * * @param seed * ?? * @throws Exception * @author huangbuji * <p /> * Create at 2014-2-8 ?4:45:26 */ @SuppressWarnings("restriction") public static void genKey(String seed) throws Exception { KeyPairGenerator keygen = KeyPairGenerator.getInstance("DSA"); SecureRandom random = new SecureRandom(); random.setSeed(seed.getBytes("utf8")); keygen.initialize(1024, random); KeyPair keyPair = keygen.generateKeyPair(); DSAPublicKeyImpl publicKey = (DSAPublicKeyImpl) keyPair.getPublic(); DSAPrivateKey privateKey = (DSAPrivateKey) keyPair.getPrivate(); DSAParams dsaParams = privateKey.getParams(); Base64 base64 = new Base64(); String p = new String(base64.encode(dsaParams.getP().toByteArray()), "utf8"); String q = new String(base64.encode(dsaParams.getQ().toByteArray()), "utf8"); String g = new String(base64.encode(dsaParams.getG().toByteArray()), "utf8"); String x = new String(base64.encode(privateKey.getX().toByteArray()), "utf8"); String y = new String(base64.encode(publicKey.getY().toByteArray()), "utf8"); System.out.println("P: " + p); System.out.println("Q: " + q); System.out.println("G: " + g); System.out.println("X: " + x); System.out.println("Y: " + y); String publicKeyString = new String(base64.encode(publicKey.getEncoded()), "utf8"); String privateKeyString = new String(base64.encode(privateKey.getEncoded()), "utf8"); System.err.println("public: " + publicKeyString); System.err.println("private: " + privateKeyString); File publicFile = new File("D:/binPublic.ky"); File privateFile = new File("D:/binPrivate.ky"); FileOutputStream out = new FileOutputStream(publicFile); out.write(publicKey.getEncoded()); out.flush(); out.close(); out = new FileOutputStream(privateFile); out.write(privateKey.getEncoded()); out.flush(); out.close(); }
From source file:FileUtils.java
public static void writeFile(byte[] bytes, File file) throws IOException { if (file.isDirectory()) { throw new IllegalArgumentException( "File '" + file.getAbsoluteFile() + "' is an existing directory. Cannot write."); }//www . j a v a2s . c o m FileOutputStream stream = new FileOutputStream(file); try { stream.write(bytes); stream.flush(); } finally { stream.close(); } }
From source file:com.ckfinder.connector.utils.ImageUtils.java
/** * writes unchanged file to disk.// ww w . j a va 2s . c o m * * @param stream - stream to read the file from * * @param destFile - file to write to * * @throws IOException when error occurs. */ private static void writeUntouchedImage(final InputStream stream, final File destFile) throws IOException { ByteArrayOutputStream byteArrayOS = new ByteArrayOutputStream(); byte[] buffer = new byte[MAX_BUFF_SIZE]; int readNum = -1; while ((readNum = stream.read(buffer)) != -1) { byteArrayOS.write(buffer, 0, readNum); } byte[] bytes = byteArrayOS.toByteArray(); byteArrayOS.close(); FileOutputStream fileOS = new FileOutputStream(destFile); fileOS.write(bytes); fileOS.flush(); fileOS.close(); }