public static String readAsString(URL url) { try { return IOHelpers.readFully(url); } catch (IOException e) { throw new RuntimeException(e); } }
public static void writeTo(OutputStream outputStream, InputStream in, boolean close) throws IOException { writeTo(outputStream, in, BUFFER_SIZE, close); }
String text = IOHelpers.readFully(rb); String updatedText = text.replaceAll("version\\s+\"([^\"]+)\"", "version \"" + value + "\""); if (!Objects.equal(text, updatedText)) { LOG.info("Loading the sha256 from " + url); try { String sha256 = IOHelpers.loadFully(new URL(url)).trim(); LOG.warn("Could not find the url in the formula to update the sha256"); IOHelpers.writeFully(rb, updatedText);
IOHelpers.copy(zip.getInputStream(entry), out); } else { IOHelpers.copy(zip.getInputStream(entry), bos); String text = new String(bos.toByteArray(), "UTF-8"); out.write(transformContents(text, replaceProperties).getBytes()); IOHelpers.close(out); } finally { if (zip != null) { IOHelpers.close(zip); String text = IOHelpers.readFully(new FileReader(pom)); for (Map.Entry<String, String> e : replaceProperties.entrySet()) { text = replaceVariable(text, e.getKey(), e.getValue()); text = text.replaceFirst("<description>(.*)</description>", "<description>" + description + "</description>"); IOHelpers.writeTo(pom, text);
protected void copyFile(File src, File dest, Replacement replaceFn, boolean isSource) throws IOException { if (replaceFn != null && isSource) { String original = IOHelpers.readFully(src); String escapedContent = original; if (original.contains("${")) { String replaced = escapedContent.replaceAll(Pattern.quote("${"), "\\${D}{"); // add Velocity expression at the beginning of the result file. // Velocity is used by mvn archetype:generate escapedContent = "#set( $D = '$' )\n" + replaced; } if (original.contains("##")) { String replaced = escapedContent.replaceAll(Pattern.quote("##"), "\\${H}"); // add Velocity expression at the beginning of the result file. // Velocity is used by mvn archetype:generate escapedContent = "#set( $H = '##' )\n" + replaced; } // do additional replacement String text = replaceFn.replace(escapedContent); IOHelpers.writeFully(dest, text); } else { if (LOG.isDebugEnabled()) { LOG.warn("Not a source dir as the extension is {}", Files.getExtension(src.getName())); } Files.copy(src, dest); } }
/** * Saves the pom.xml if its been changed * * @return true if the pom was modified * @throws IOException */ public boolean saveIfChanged() throws IOException { if (updated) { LOG.info("Updating " + pom); try { IOHelpers.writeFully(pom, doc.toXML()); } catch (Exception e) { throw new IOException("failed to save " + pom + ". " + e, e); } } return updated; }
public static void copy(InputStream inputStream, OutputStream outputStream) throws IOException { try { byte[] buffer = new byte[8192]; int len; for (; ;) { len = inputStream.read(buffer); if (len > 0) { outputStream.write(buffer, 0, len); } else { outputStream.flush(); break; } } } finally { close(inputStream, outputStream); } }
IOHelpers.copy(zip, bos);
/** * Saves the pom.xml if its been changed * * @return true if the pom was modified * @throws IOException */ public boolean saveIfChanged() throws IOException { if (updated) { LOG.info("Updating " + pom); try { IOHelpers.writeFully(pom, doc.toXML()); } catch (Exception e) { throw new IOException("failed to save " + pom + ". " + e, e); } } return updated; }
public static void copy(Reader reader, Writer writer) throws IOException { try { char[] buffer = new char[8192]; int len; for (; ;) { len = reader.read(buffer); if (len > 0) { writer.write(buffer, 0, len); } else { writer.flush(); break; } } } finally { close(reader, writer); } }
IOHelpers.copy(new InputStreamReader(getClass().getResourceAsStream("default-archetype-pom.xml")), sw); Document pomDocument = archetypeUtils.parseXml(new InputSource(new StringReader(sw.toString())));
public static String readFully(File file) throws IOException { if (!file.isFile()) { return null; } InputStream in = new FileInputStream(file); return readFully(in); }
public static void savePrettyJson(File file, Object value) throws IOException { // lets use the node layout NpmJsonPrettyPrinter printer = new NpmJsonPrettyPrinter(); ObjectMapper objectMapper = createPrettyJsonObjectMapper(); objectMapper.setDefaultPrettyPrinter(printer); String json = objectMapper.writer().writeValueAsString(value); IOHelpers.writeFully(file, json + System.lineSeparator()); }
protected String defaultArchetypeXmlText() throws IOException { InputStreamReader reader = new InputStreamReader(getClass().getResourceAsStream("default-archetype-descriptor.xml")); StringWriter sw = new StringWriter(); try { IOHelpers.copy(reader, sw); } finally { IOHelpers.close(reader, sw); } return sw.toString(); }
public static void writeTo(File file, InputStream in) throws IOException { writeTo(file, in, BUFFER_SIZE); }
IOHelpers.close(is);
public static String readFully(InputStream in) throws IOException { Reader r = new BufferedReader(new InputStreamReader(in)); return readFully(r); }
/** * Git tends to ignore empty directories so lets add a dummy file to empty folders to keep them in git */ public static void addDummyFileToEmptyFolders(File dir) { if (dir != null && dir.isDirectory()) { File[] children = dir.listFiles(); if (children == null || children.length == 0) { File dummyFile = new File(dir, ".gitkeep"); try { IOHelpers.writeFully(dummyFile, "This file is only here to avoid git removing empty folders\nOnce there are files in this folder feel free to delete this file!"); } catch (IOException e) { LOG.warn("Failed to write file " + dummyFile + ". " + e, e); } } else { for (File child : children) { if (child.isDirectory()) { addDummyFileToEmptyFolders(child); } } } } }
private String groovyArchetypeXmlText() throws IOException { InputStreamReader reader = new InputStreamReader(getClass().getResourceAsStream("groovy-archetype-descriptor.xml")); StringWriter sw = new StringWriter(); try { IOHelpers.copy(reader, sw); } finally { IOHelpers.close(reader, sw); } return sw.toString(); }