/** * Get a file from workspace. * * @param fileName The name of the file to download from workspace. You can * also access files which are in sub folders of the workspace. * @return The string which contains the content of the file. * @throws IOException in case of an error. */ public String getFileFromWorkspace(String fileName) throws IOException { InputStream is = client.getFile(URI.create(url + "/ws/" + fileName)); ByteArrayOutputStream result = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int length; while ((length = is.read(buffer)) != -1) { result.write(buffer, 0, length); } return result.toString("UTF-8"); }
public InputStream downloadArtifact(Artifact a) throws IOException, URISyntaxException { // We can't just put the artifact's relative path at the end of the url // string, as there could be characters that need to be escaped. URI uri = new URI(getUrl()); String artifactPath = uri.getPath() + "artifact/" + a.getRelativePath(); URI artifactUri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), artifactPath, "", ""); return client.getFile(artifactUri); }