private File setCompressor(CacheFile c, HttpServletResponse rsp, String type, FE<OutputStream,OutputStream> gen) throws Exception { rsp.setHeader("Content-Encoding", type); File f = new File(c.file.getParentFile(), c.file.getName() + "__" + type + "__"); if (f.isFile() && f.lastModified() >= c.file.lastModified()) { return f; } File t = IO.createTempFile(c.file.getParentFile(), "tmp", "." + type); try (FileOutputStream fout = new FileOutputStream(t)) { try (OutputStream out = gen.get(fout);) { IO.copy(c.file, out); out.flush(); } } Files.move(t.toPath(), f.toPath(), StandardCopyOption.REPLACE_EXISTING); t.renameTo(f); return f; }
public void save(File location) throws IOException { if (location.getName() .endsWith(".gz")) compress = true; IO.mkdirs(location.getParentFile()); File tmp = IO.createTempFile(location.getParentFile(), "index", ".xml"); try (OutputStream out = IO.outputStream(tmp)) { save(out); } IO.rename(tmp, location); }
public void save(File location) throws IOException { if (location.getName() .endsWith(".gz")) compress = true; IO.mkdirs(location.getParentFile()); File tmp = IO.createTempFile(location.getParentFile(), "index", ".xml"); try (OutputStream out = IO.outputStream(tmp)) { save(out); } IO.rename(tmp, location); }
@Override public File call() { try { String uri = URLDecoder.decode(path.substring(1), "UTF-8"); URL url = new URL(uri); URLConnection con = url.openConnection(); con.setConnectTimeout(10000); con.setRequestProperty("Accept-Encoding", "deflate, gzip"); File tmp = IO.createTempFile(cacheFile, "path", ".tmp"); InputStream in = con.getInputStream(); String encoding = con.getContentEncoding(); if ("deflate".equalsIgnoreCase(encoding)) { in = new DeflaterInputStream(in); } else if ("gzip".equalsIgnoreCase(encoding)) { in = new ZipInputStream(in); } IO.copy(in, tmp); IO.rename(tmp, cached); cached.setLastModified(con.getLastModified() + 1000); return cached; } catch (Exception e) { throw new RuntimeException(new InternalServer500Exception(e)); } }
void download0(URI url, File path, byte[] sha) throws Exception { IO.mkdirs(path.getParentFile()); File tmp = IO.createTempFile(path.getParentFile(), "tmp", ".jar"); URL u = url.toURL();
void download0(URI url, File path, byte[] sha) throws Exception { IO.mkdirs(path.getParentFile()); File tmp = IO.createTempFile(path.getParentFile(), "tmp", ".jar"); URL u = url.toURL();
tmpFile = IO.createTempFile(storageDir, "put", ".bnd"); IO.copy(dis, tmpFile);
tmpFile = IO.createTempFile(storageDir, "put", ".bnd"); IO.copy(dis, tmpFile);
void download0(URI url, File path, byte[] sha) throws Exception { path.getParentFile().mkdirs(); File tmp = IO.createTempFile(path.getParentFile(), "tmp", ".jar"); URL u = url.toURL();
void download0(URI url, File path, byte[] sha) throws Exception { path.getParentFile().mkdirs(); File tmp = IO.createTempFile(path.getParentFile(), "tmp", ".jar"); URL u = url.toURL();
File tmpFile = IO.createTempFile(root, "put", ".jar"); try (DigestInputStream dis = new DigestInputStream(stream, MessageDigest.getInstance("SHA-1"))) { IO.copy(dis, tmpFile);
File tmpFile = IO.createTempFile(root, "put", ".jar"); try (DigestInputStream dis = new DigestInputStream(stream, MessageDigest.getInstance("SHA-1"))) { IO.copy(dis, tmpFile);
File tmpFile = IO.createTempFile(root, "put", ".jar"); try { DigestInputStream dis = new DigestInputStream(stream, MessageDigest.getInstance("SHA-1"));
File tmpFile = IO.createTempFile(root, "put", ".jar"); try { DigestInputStream dis = new DigestInputStream(stream, MessageDigest.getInstance("SHA-1"));
File tmpFile = IO.createTempFile(root, "put", ".jar"); try { DigestInputStream dis = new DigestInputStream(stream, MessageDigest.getInstance("SHA-1"));