/** * @param file * @return The byte array * @throws IOException */ public static byte[] readToByteArray(File file) throws IOException { return readToByteArray(new FileInputStream(file)); }
/** * Cleans up temporary files. */ public void cleanUp() { this.jythonJarFile = null; this.xbayaJarFile = null; if (this.tmpJarDirectory != null) { try { IOUtil.deleteDirectory(this.tmpJarDirectory); } catch (RuntimeException e) { logger.error(e.getMessage(), e); } } }
/** * Returns the content of a specified file as a String. * * @param file * @return the content of a specified file as a String * @throws IOException */ public static String readFileToString(File file) throws IOException { FileReader reader = new FileReader(file); return readToString(reader); }
public static void saveJSON(JsonElement jsonElement, File file) throws IOException { IOUtil.writeToFile(jsonElementToString(jsonElement), file); }
/** * @param content * @param file * @throws IOException */ public static void writeToFile(String content, File file) throws IOException { FileWriter fw = new FileWriter(file); writeToWriter(content, fw); }
/** * Reads a specified file and creates a graph. * * @param file * @return The graph created * @throws GraphException * @throws IOException */ public static WSGraph createGraph(File file) throws GraphException, IOException { String graphString = IOUtil.readFileToString(file); return createGraph(graphString); }
logger.debug("file: " + file); InputStream stream = url.openStream(); IOUtil.writeToFile(stream, file); JarFile jarFile = new JarFile(file); return jarFile;
/** * @param content * @param file * @throws IOException */ public static void writeToFile(String content, File file) throws IOException { FileWriter fw = new FileWriter(file); writeToWriter(content, fw); }
/** * @param file * @return The XmlElement in the document. * @throws IOException */ public static org.xmlpull.infoset.XmlElement loadXML(File file) throws IOException { String xmlText = IOUtil.readFileToString(file); XmlDocument document = BUILDER.parseString(xmlText); return document.getDocumentElement(); }
/** * Returns a String read from a specified InputStream. * * @param stream * The specified InputStream * @return The String read from the specified InputStream * @throws IOException */ public static String readToString(InputStream stream) throws IOException { return readToString(new InputStreamReader(stream)); }
/** * @param file * @return The byte array * @throws IOException */ public static byte[] readToByteArray(File file) throws IOException { return readToByteArray(new FileInputStream(file)); }
/** * Saves a specified XmlElement to a specified file. * * @param element * @param file * @throws IOException */ public static void saveXML(org.xmlpull.infoset.XmlElement element, File file) throws IOException { XmlDocument document = BUILDER.newDocument(); document.setDocumentElement(element); String xmlText = BUILDER.serializeToStringPretty(document); IOUtil.writeToFile(xmlText, file); }
/** * @param path * @return <code>true</code> if and only if the file or directory is successfully deleted; <code>false</code> * otherwise */ public static boolean deleteDirectory(File path) { if (path.exists()) { File[] files = path.listFiles(); for (File file : files) { if (file.isDirectory()) { deleteDirectory(file); } else { file.delete(); } } } return path.delete(); }
/** * @param path * @param content * @throws IOException */ public static void writeToFile(String content, String path) throws IOException { logger.debug("Path:" + path + " Content:" + content); FileWriter fw = new FileWriter(path); writeToWriter(content, fw); }
/** * @param file * @return The list of components defined in the specified file. * @throws ComponentException * @throws ComponentRegistryException */ public List<WSComponent> getComponents(File file) throws ComponentException, ComponentRegistryException { try { String compString = IOUtil.readFileToString(file); List<WSComponent> components = WSComponentFactory .createComponents(compString); return components; } catch (IOException e) { throw new ComponentRegistryException(e); } }
/** * Returns the content of a specified file as a String. * * @param path * @return the content of a specified file as a String * @throws IOException */ public static String readFileToString(String path) throws IOException { FileReader read = new FileReader(path); return readToString(read); }
/** * Gets the default proxy certificate. * * @return Default my proxy credentials. * @throws org.apache.airavata.gfac.GFacException If an error occurred while retrieving credentials. * @throws org.apache.airavata.common.exception.ApplicationSettingsException */ public SSHCredential getDefaultCredentials() throws GFacException, ApplicationSettingsException, IOException { Properties configurationProperties = ServerSettings.getProperties(); String sshUserName = configurationProperties.getProperty(Constants.SSH_USER_NAME); this.getRequestData().setRequestUser(sshUserName); this.privateKeyFile = configurationProperties.getProperty(Constants.SSH_PRIVATE_KEY); this.publicKeyFile = configurationProperties.getProperty(Constants.SSH_PUBLIC_KEY); this.passPhrase = configurationProperties.getProperty(Constants.SSH_PRIVATE_KEY_PASS); this.getRequestData().setRequestUser(sshUserName); return new SSHCredential(IOUtil.readToByteArray(new File(this.privateKeyFile)), IOUtil.readToByteArray(new File(this.publicKeyFile)), this.passPhrase, requestData.getGatewayId(), sshUserName); }
/** * Saves a specified XmlElement to a specified file. * * @param element * @param file * @throws IOException */ public static void saveXML(org.xmlpull.infoset.XmlElement element, File file) throws IOException { XmlDocument document = BUILDER.newDocument(); document.setDocumentElement(element); String xmlText = BUILDER.serializeToStringPretty(document); IOUtil.writeToFile(xmlText, file); }
/** * @param path * @return <code>true</code> if and only if the file or directory is successfully deleted; <code>false</code> * otherwise */ public static boolean deleteDirectory(File path) { if (path.exists()) { File[] files = path.listFiles(); for (File file : files) { if (file.isDirectory()) { deleteDirectory(file); } else { file.delete(); } } } return path.delete(); }
/** * @param path * @param content * @throws IOException */ public static void writeToFile(String content, String path) throws IOException { logger.debug("Path:" + path + " Content:" + content); FileWriter fw = new FileWriter(path); writeToWriter(content, fw); }