static void copyFile(final File file, final File backup) throws IOException { final FileInputStream fis = new FileInputStream(file); try { final FileOutputStream fos = new FileOutputStream(backup); try { StreamUtils.copyStream(fis, fos); fos.flush(); fos.getFD().sync(); fos.close(); } finally { StreamUtils.safeClose(fos); } } finally { StreamUtils.safeClose(fis); } }
/** {@inheritDoc} */ @Override protected void sendRequest(int protocolVersion, OutputStream outputStream) throws IOException { outputStream.write(StandaloneClientProtocol.PARAM_DEPLOYMENT_NAME); StreamUtils.writeUTFZBytes(outputStream, name); outputStream.write(StandaloneClientProtocol.PARAM_DEPLOYMENT_RUNTIME_NAME); StreamUtils.writeUTFZBytes(outputStream, runtimeName); outputStream.write(StandaloneClientProtocol.PARAM_DEPLOYMENT_CONTENT); try { byte[] buffer = new byte[8192]; int read; while ((read = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, read); } } finally { safeClose(inputStream); } }
@Override public synchronized void copyStream(final DataOutput output) throws IOException { final FileInputStream is = new FileInputStream(temp); try { StreamUtils.copyStream(is, output); } finally { StreamUtils.safeClose(is); } }
@Override public void copyStream(final DataOutput output) throws IOException { final FileInputStream is = new FileInputStream(file); try { StreamUtils.copyStream(is, output); is.close(); } finally { StreamUtils.safeClose(is); } }
@Override public synchronized int initialize() throws IOException { final ByteArrayOutputStream os = new ByteArrayOutputStream(); try { StreamUtils.copyStream(original, os); } finally { if(autoClose) { StreamUtils.safeClose(original); } } data = os.toByteArray(); return data.length; }
File trustStoreFile = new File(trustStore); if (trustStoreFile.exists()) { fis = new FileInputStream(trustStoreFile); theTrustStore.load(fis, trustStorePassword.toCharArray()); StreamUtils.safeClose(fis); fis = null; } else { fos = new FileOutputStream(trustStoreFile); theTrustStore.store(fos, trustStorePassword.toCharArray()); throw new IllegalStateException("Unable to operate on trust store.", e); } finally { StreamUtils.safeClose(fis); StreamUtils.safeClose(fos);
File trustStoreFile = new File(trustStore); if (trustStoreFile.exists()) { fis = new FileInputStream(trustStoreFile); theTrustStore.load(fis, trustStorePassword.toCharArray()); } else { throw new IllegalStateException("Unable to operate on trust store.", e); } finally { StreamUtils.safeClose(fis);
protected File copyStream(final InputStream is, final File tempDir) throws IOException { final File temp = File.createTempFile("upload", "temp", tempDir); if (is != null) { final FileOutputStream os = new FileOutputStream(temp); try { StreamUtils.copyStream(is, os); os.close(); } finally { StreamUtils.safeClose(os); } } return temp; } }
int rc; is = jarFile.getInputStream(entry); fos = new FileOutputStream(file); while ((rc = is.read(buf)) > -1) { fos.write(buf,0,rc); fos.flush(); } finally { StreamUtils.safeClose(is); StreamUtils.safeClose(fos);
public static byte[] readBytes(File f) throws OperationFormatException { byte[] bytes; FileInputStream is = null; try { is = new FileInputStream(f); bytes = new byte[(int) f.length()]; int read = is.read(bytes); if(read != bytes.length) { throw new OperationFormatException("Failed to read bytes from " + f.getAbsolutePath() + ": " + read + " from " + f.length()); } } catch (Exception e) { throw new OperationFormatException("Failed to read file " + f.getAbsolutePath(), e); } finally { StreamUtils.safeClose(is); } return bytes; }
JarOutputStream jar = null; try { jar = new JarOutputStream(new FileOutputStream(moduleJar), manifest); jar.flush(); } finally { StreamUtils.safeClose(jar);
/** * Send a operation response. * * @param context the request context * @param responseType the response type * @param response the operation response * @throws IOException for any error */ static void sendResponse(final ManagementRequestContext<RegistrationContext> context, final byte responseType, final ModelNode response) throws IOException { final ManagementResponseHeader header = ManagementResponseHeader.create(context.getRequestHeader()); final FlushableDataOutput output = context.writeMessage(header); try { sendResponse(output, responseType, response); } finally { StreamUtils.safeClose(output); } }
private void shutdown(Throwable error) { StreamUtils.safeClose(this); this.error = error; } }
public static <A> void writeResponse(final ResponseWriter writer, final ManagementRequestContext<A> context, final ManagementResponseHeader header) throws IOException { final FlushableDataOutput output = context.writeMessage(header); try { writer.write(output); output.writeByte(ManagementProtocol.RESPONSE_END); output.close(); } finally { StreamUtils.safeClose(output); } }
@Override public void execute(final ManagementRequestContext<ExecuteRequestContext> context) throws Exception { FlushableDataOutput output = null; try { MGMT_OP_LOGGER.tracef("Transmitting response for %d", context.getOperationId()); final ManagementResponseHeader header = ManagementResponseHeader.create(context.getRequestHeader()); output = context.writeMessage(header); // response type output.writeByte(responseType); // operation result response.writeExternal(output); // response end output.writeByte(ManagementProtocol.RESPONSE_END); output.close(); } catch (IOException toCache) { exceptionHolder.exception = toCache; } finally { StreamUtils.safeClose(output); latch.countDown(); } } }, false);
protected ByteArrayOutputStream copyStream(final InputStream is) throws IOException { final ByteArrayOutputStream bout = new ByteArrayOutputStream(); if(is != null) { StreamUtils.copyStream(is, bout); } return bout; }
File trustStoreFile = new File(trustStore); if (trustStoreFile.exists()) { fis = new FileInputStream(trustStoreFile); theTrustStore.load(fis, trustStorePassword.toCharArray()); StreamUtils.safeClose(fis); fis = null; } else { fos = new FileOutputStream(trustStoreFile); theTrustStore.store(fos, trustStorePassword.toCharArray()); throw new IllegalStateException("Unable to operate on trust store.", e); } finally { StreamUtils.safeClose(fis); StreamUtils.safeClose(fos);
File trustStoreFile = new File(trustStore); if (trustStoreFile.exists()) { fis = new FileInputStream(trustStoreFile); theTrustStore.load(fis, trustStorePassword.toCharArray()); } else { throw new IllegalStateException("Unable to operate on trust store.", e); } finally { StreamUtils.safeClose(fis);
protected File copyStream(final InputStream is, final File tempDir) throws IOException { final File temp = File.createTempFile("upload", "temp", tempDir); if (is != null) { final FileOutputStream os = new FileOutputStream(temp); try { StreamUtils.copyStream(is, os); os.close(); } finally { StreamUtils.safeClose(os); } } return temp; } }
@Override public void copyStream(final DataOutput output) throws IOException { final FileInputStream is = new FileInputStream(file); try { StreamUtils.copyStream(is, output); is.close(); } finally { StreamUtils.safeClose(is); } }