use of java.io.FileOutputStream in project tomcat by apache.
the class ManagerServlet method uploadWar.
/**
* Upload the WAR file included in this request, and store it at the
* specified file location.
*
* @param writer Writer to render to
* @param request The servlet request we are processing
* @param war The file into which we should store the uploaded WAR
* @param smClient The StringManager used to construct i18n messages based
* on the Locale of the client
*
* @exception IOException if an I/O error occurs during processing
*/
protected void uploadWar(PrintWriter writer, HttpServletRequest request, File war, StringManager smClient) throws IOException {
if (war.exists() && !war.delete()) {
String msg = smClient.getString("managerServlet.deleteFail", war);
throw new IOException(msg);
}
try (ServletInputStream istream = request.getInputStream();
BufferedOutputStream ostream = new BufferedOutputStream(new FileOutputStream(war), 1024)) {
byte[] buffer = new byte[1024];
while (true) {
int n = istream.read(buffer);
if (n < 0) {
break;
}
ostream.write(buffer, 0, n);
}
} catch (IOException e) {
if (war.exists() && !war.delete()) {
writer.println(smClient.getString("managerServlet.deleteFail", war));
}
throw e;
}
}
use of java.io.FileOutputStream in project zeppelin by apache.
the class ScreenCaptureHtmlUnitDriver method getScreenshotAs.
@Override
@SuppressWarnings("unchecked")
public <X> X getScreenshotAs(OutputType<X> target) throws WebDriverException {
byte[] archive = new byte[0];
try {
archive = downloadCssAndImages(getWebClient(), (HtmlPage) getCurrentWindow().getEnclosedPage());
} catch (Exception e) {
LOGGER.error("Exception in ScreenCaptureHtmlUnitDriver while getScreenshotAs ", e);
}
if (target.equals(OutputType.BASE64)) {
return target.convertFromBase64Png(new Base64Encoder().encode(archive));
}
if (target.equals(OutputType.FILE)) {
File f = new File("screen.tmp");
try {
FileOutputStream scr = new FileOutputStream(f);
scr.write(archive);
scr.close();
} catch (IOException e) {
throw new WebDriverException(e);
}
return (X) f;
}
return (X) archive;
}
use of java.io.FileOutputStream in project zookeeper by apache.
the class FileSnap method serialize.
/**
* serialize the datatree and session into the file snapshot
* @param dt the datatree to be serialized
* @param sessions the sessions to be serialized
* @param snapShot the file to store snapshot into
*/
public synchronized void serialize(DataTree dt, Map<Long, Integer> sessions, File snapShot) throws IOException {
if (!close) {
OutputStream sessOS = new BufferedOutputStream(new FileOutputStream(snapShot));
CheckedOutputStream crcOut = new CheckedOutputStream(sessOS, new Adler32());
//CheckedOutputStream cout = new CheckedOutputStream()
OutputArchive oa = BinaryOutputArchive.getArchive(crcOut);
FileHeader header = new FileHeader(SNAP_MAGIC, VERSION, dbId);
serialize(dt, sessions, oa, header);
long val = crcOut.getChecksum().getValue();
oa.writeLong(val, "val");
oa.writeString("/", "path");
sessOS.flush();
crcOut.close();
sessOS.close();
}
}
use of java.io.FileOutputStream in project cw-omnibus by commonsguy.
the class AbstractFileProvider method copy.
static void copy(InputStream in, File dst) throws IOException {
FileOutputStream out = new FileOutputStream(dst);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) >= 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
}
use of java.io.FileOutputStream in project cw-omnibus by commonsguy.
the class FilesCPDemo method copy.
private static void copy(InputStream in, File dst) throws IOException {
FileOutputStream out = new FileOutputStream(dst);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
}
Aggregations