private String readContents(final URL resource) throws IOException { return IO.slurp(resource); }
public static Properties readProperties(final File resource, final Properties properties) throws IOException { return readProperties(read(resource), properties); }
private static void updateBinFile(final File binDir, final String binFile, final String changes) throws IOException { final URL agent = getResource(changes); final File catalinaSh = file(binDir, binFile); String content = IO.slurp(catalinaSh); content = content.replace("# ----- Execute The Requested Command", IO.slurp(agent)); IO.copy(IO.read(content), catalinaSh); }
private void writeRaXml(final ConnectorModule connectorModule) { try { final Connector connector = connectorModule.getConnector(); final File tempFile = tempFile("ra-", connectorModule.getModuleId() + ".xml"); final OutputStream out = IO.write(tempFile); try { final JAXBContext ctx = JAXBContextFactory.newInstance(Connector.class); final Marshaller marshaller = ctx.createMarshaller(); marshaller.marshal(connector, out); logger.info("Dumping Generated ra.xml to: " + tempFile.getAbsolutePath()); } catch (final JAXBException e) { // no-op } finally { IO.close(out); } } catch (final IOException e) { // no-op } }
public static void copy(final File from, final File to) throws IOException { if (!from.isDirectory()) { final FileOutputStream fos = new FileOutputStream(to); try { copy(from, fos); } finally { close(fos); } } else { copyDirectory(from, to); } }
public static String readString(final File file) throws IOException { final FileReader in = new FileReader(file); try { final BufferedReader reader = new BufferedReader(in); return reader.readLine(); } finally { close(in); } }
private static File copy(final File file, final File lib) throws IOException { final File dest = new File(lib, file.getName()); if (dest.exists()) { return dest; } IO.copy(file, dest); return dest; }
private void installLoggingPropertiesFile(final File loggingPropertiesFile) throws IOException { final String name = STANDALONE_PROPERTIES_FILE + LOGGING_PROPERTIES_FILE; final URL resource = Thread.currentThread().getContextClassLoader().getResource(name); if (resource == null) { System.err.println("FATAL ERROR WHILE CONFIGURING LOGGING!!!. MISSING RESOURCE " + name); return; } final Properties props = IO.readProperties(resource); preprocessProperties(props); final OutputStream out = IO.write(loggingPropertiesFile); try { props.store(out, "OpenEJB Default Log4j Configuration"); } finally { IO.close(out); } PropertyConfigurator.configure(props); } }
public static void unzip(final File zipFile, final File destination, final boolean noparent) throws IOException { Files.dir(destination); Files.writable(destination); Files.file(zipFile); Files.readable(zipFile); final InputStream read = IO.read(zipFile); try { unzip(read, destination, noparent); } finally { IO.close(read); } }
private Properties loadProperties(final URL resource) throws IOException { return IO.readProperties(resource); }
private static void rename(final File directory, final String from, final String to) throws IOException { System.out.println(String.format("Renaming %s to %s in directory %s", from, to, directory)); if (!new File(directory, from).renameTo(new File(directory, to))) { IO.copy(new File(directory, from), new File(directory, to)); IO.delete(new File(directory, from)); } }
@Override public InputStream get() throws IOException { return IO.read(url); } }
public static ZipOutputStream zip(final File file) throws IOException { final OutputStream write = write(file); return new ZipOutputStream(write); }