protected File downloadBlueprintOrSpring() throws Exception { // when downloading an embedded blueprint or spring xml file, then it must be as a temporary file File dir = new File(System.getProperty("karaf.data"), "tmp"); dir.mkdirs(); File tmpFile = File.createTempFile("download-", null, dir); try (InputStream is = new URL(url).openStream(); OutputStream os = new FileOutputStream(tmpFile)) { StreamUtils.copy(is, os); } return tmpFile; }
protected void copy(File sourceFile, File destFile) { File targetDir = destFile.getParentFile(); ensureDirExists(targetDir); try (InputStream is = Files.newInputStream(sourceFile.toPath())) { try (OutputStream bos = Files.newOutputStream(destFile.toPath())) { StreamUtils.copy(is, bos); } } catch (IOException e) { throw new RuntimeException(e.getMessage(), e); } }
protected void copy(File sourceFile, File destFile) { File targetDir = destFile.getParentFile(); ensureDirExists(targetDir); try (InputStream is = Files.newInputStream(sourceFile.toPath())) { try (OutputStream bos = Files.newOutputStream(destFile.toPath())) { StreamUtils.copy(is, bos); } } catch (IOException e) { throw new RuntimeException(e.getMessage(), e); } }
/** * Extract an entry from a KAR file * * @param is * @param zipEntry * @param dest * @return * @throws Exception */ private static File extract(InputStream is, ZipEntry zipEntry, File dest) throws Exception { if (zipEntry.isDirectory()) { LOGGER.debug("Creating directory {}", dest.getName()); dest.mkdirs(); } else { dest.getParentFile().mkdirs(); FileOutputStream out = new FileOutputStream(dest); StreamUtils.copy(is, out); out.close(); } return dest; }
private void copyBinaryResourceToDir(String resource, File target, Map<String, URL> resources, boolean printOutput) throws IOException { File outFile = new File(target, resource); if( !outFile.exists() ) { logDebug("Creating file: %s", printOutput, outFile.getPath()); try ( InputStream is = getResourceStream(resource, resources); OutputStream os = new FileOutputStream(outFile) ) { StreamUtils.copy(is, os); } } }
private void copyBinaryResourceToDir(String resource, File target, Map<String, URL> resources, boolean printOutput) throws IOException { File outFile = new File(target, resource); if( !outFile.exists() ) { logDebug("Creating file: %s", printOutput, outFile.getPath()); try ( InputStream is = getResourceStream(resource, resources); OutputStream os = new FileOutputStream(outFile) ) { StreamUtils.copy(is, os); } } }
@Override public Object execute() throws Exception { File etcFolder = new File(System.getProperty("karaf.etc")); File file = new File(etcFolder, finalname); if (file.exists()) { if (!override) { throw new IllegalArgumentException("Configuration file {} already exists " + finalname); } else { System.out.println("Overriding configuration file " + finalname); } } else { System.out.println("Creating configuration file " + finalname); } try (InputStream is = new BufferedInputStream(new URL(url).openStream())) { if (!file.exists()) { File parentFile = file.getParentFile(); if (parentFile != null) { parentFile.mkdirs(); } file.createNewFile(); } try (FileOutputStream fop = new FileOutputStream(file)) { StreamUtils.copy(is, fop); } } catch (RuntimeException | MalformedURLException e) { throw e; } return null; }
private void copyResourceToJar(JarOutputStream jos, URI location, Map<URI, Integer> locationMap) { if (locationMap.containsKey(location)) { return; } try { String noPrefixLocation = location.toString().substring(location.toString().lastIndexOf(":") + 1); Parser parser = new Parser(noPrefixLocation); String path = "repository/" + parser.getArtifactPath(); jos.putNextEntry(new JarEntry(path)); try ( InputStream is = location.toURL().openStream() ) { StreamUtils.copy(is, jos); } locationMap.put(location, 1); } catch (Exception e) { LOGGER.error("Error adding " + location, e); } }
@Override public void install(String url, String finalname, boolean override) throws MBeanException { try { File etcFolder = new File(System.getProperty("karaf.etc")); File file = new File(etcFolder, finalname); if (file.exists()) { if (!override) { throw new IllegalArgumentException("Configuration file {} already exists " + finalname); } } try (InputStream is = new BufferedInputStream(new URL(url).openStream())) { if (!file.exists()) { File parentFile = file.getParentFile(); if (parentFile != null) { parentFile.mkdirs(); } file.createNewFile(); } try (FileOutputStream fop = new FileOutputStream(file)) { StreamUtils.copy(is, fop); } } catch (RuntimeException | MalformedURLException e) { throw e; } } catch (Exception e) { throw new MBeanException(null, e.toString()); } }
@Override public Object execute() throws Exception { File etcFolder = new File(System.getProperty("karaf.etc")); File file = new File(etcFolder, finalname); if (file.exists()) { if (!override) { throw new IllegalArgumentException("Configuration file {} already exists " + finalname); } else { System.out.println("Overriding configuration file " + finalname); } } else { System.out.println("Creating configuration file " + finalname); } try (InputStream is = new BufferedInputStream(new URL(url).openStream())) { if (!file.exists()) { File parentFile = file.getParentFile(); if (parentFile != null) { parentFile.mkdirs(); } file.createNewFile(); } try (FileOutputStream fop = new FileOutputStream(file)) { StreamUtils.copy(is, fop); } } catch (RuntimeException | MalformedURLException e) { throw e; } return null; }
@Override public void install(String url, String finalname, boolean override) throws MBeanException { try { File etcFolder = new File(System.getProperty("karaf.etc")); File file = new File(etcFolder, finalname); if (file.exists()) { if (!override) { throw new IllegalArgumentException("Configuration file {} already exists " + finalname); } } try (InputStream is = new BufferedInputStream(new URL(url).openStream())) { if (!file.exists()) { File parentFile = file.getParentFile(); if (parentFile != null) { parentFile.mkdirs(); } file.createNewFile(); } try (FileOutputStream fop = new FileOutputStream(file)) { StreamUtils.copy(is, fop); } } catch (RuntimeException | MalformedURLException e) { throw e; } } catch (Exception e) { throw new MBeanException(null, e.toString()); } }
OutputStream out = new FileOutputStream(destination) ) { StreamUtils.copy(in, out);
FileOutputStream fop = new FileOutputStream(file) ) { StreamUtils.copy(is, fop);
OutputStream out = new FileOutputStream(destination) ) { StreamUtils.copy(in, out);
FileInputStream inputStream = new FileInputStream(file); OutputStream outputStream = destination.add("log/" + file.getName()); StreamUtils.copy(inputStream, outputStream);
try (InputStream is = urlObj.openStream(); OutputStream os = new FileOutputStream(tmpFile)) { StreamUtils.copy(is, os);
InputStream fis = url.openStream() ) { StreamUtils.copy(fis, out);
InputStream fis = url.openStream() ) { StreamUtils.copy(fis, out);