List of usage examples for java.nio.file Files readAllBytes
public static byte[] readAllBytes(Path path) throws IOException
From source file:com.smartsheet.api.internal.ReportResourcesImplTest.java
@Test public void testGetReportAsCsv() throws SmartsheetException, IOException { File file = new File("src/test/resources/getExcel.xls"); server.setResponseBody(file);// w w w. j a v a 2 s .com server.setContentType("text/csv"); ByteArrayOutputStream output = new ByteArrayOutputStream(); reportResources.getReportAsExcel(4583173393803140L, output); assertNotNull(output); assertTrue(output.toByteArray().length > 0); byte[] data = Files.readAllBytes(Paths.get(file.getPath())); assertEquals(data.length, output.toByteArray().length); }
From source file:test.TestJavaService.java
/** * Make the special JSON encoding with both a schema and some number of CSV files must be provided * TODO at present there is no way to send "format" or "delimiter" members * @param schemaString a String containing the JSON schema * @param files the list of file names which are to be read to obtain CSV and whose names are to be decomposed to * form type (table) names//from www . j a v a 2 s .co m * @return the JSON encoding to send * @throws IOException */ private static String makeSpecialJson(String schemaString, List<String> files) throws IOException { JsonObject result = new JsonObject(); JsonObject schema = new JsonParser().parse(schemaString).getAsJsonObject(); result.add("schema", schema); JsonObject data = new JsonObject(); result.add("data", data); for (String file : files) { Path path = Paths.get(file); String csv = new String(Files.readAllBytes(path)); String table = path.getFileName().toString(); if (table.endsWith(".csv")) table = table.substring(0, table.length() - 4); data.add(table, new JsonPrimitive(csv)); } return result.toString(); }
From source file:com.bmwcarit.barefoot.tracker.TrackerServerTest.java
@Test public void testTrackerServer() throws IOException, JSONException, InterruptedException { Server server = new Server(); InetAddress host = InetAddress.getLocalHost(); Properties properties = new Properties(); properties.load(new FileInputStream("config/tracker.properties")); int port = Integer.parseInt(properties.getProperty("server.port")); server.start();// w w w . j ava 2s . c om { String json = new String( Files.readAllBytes(Paths.get(ServerTest.class.getResource("x0001-015.json").getPath())), Charset.defaultCharset()); List<MatcherSample> samples = new LinkedList<>(); JSONArray jsonsamples = new JSONArray(json); for (int i = 0; i < jsonsamples.length(); ++i) { MatcherSample sample = new MatcherSample(jsonsamples.getJSONObject(i)); samples.add(sample); sendSample(host, port, sample.toJSON()); } String id = new MatcherSample(jsonsamples.getJSONObject(0)).id(); MatcherKState state = requestState(host, port, id); MatcherKState check = TrackerControl.getServer().getMatcher().mmatch(samples, 0, 0); assertEquals(check.sequence().size(), state.sequence().size()); for (int i = 0; i < state.sequence().size(); i++) { assertEquals(check.sequence().get(i).point().edge().id(), state.sequence().get(i).point().edge().id()); assertEquals(check.sequence().get(i).point().fraction(), state.sequence().get(i).point().fraction(), 1E-10); } } server.stop(); }
From source file:de.dennishoersch.web.css.images.ImagesInliner.java
private String inlineUrl(String url) throws IOException { Path path = _pathResolver.resolve(url); if (path == null) { logger.log(Level.WARNING, "Could not inline URL '" + url + "'!"); return null; }//from w w w . j a v a2 s . c om String contentType = Files.probeContentType(path); if (!contentType.contains("image")) { return null; } byte[] bytes = Files.readAllBytes(path); return contentType + ";base64," + org.apache.commons.codec.binary.Base64.encodeBase64String(bytes); }
From source file:de.thingweb.desc.ThingDescriptionParser.java
public static Thing fromFile(String fname) throws FileNotFoundException, IOException { Path path = Paths.get(fname); byte[] data = Files.readAllBytes(path); return fromBytes(data); }
From source file:com.nike.cerberus.operation.core.UploadCertFilesOperation.java
private String getFileContents(final Path path, final String filename) { Preconditions.checkNotNull(path);//from w ww . ja v a 2 s. c o m Preconditions.checkNotNull(filename); File file = new File(path.toString(), filename); if (file.exists() && file.canRead()) { try { return new String(Files.readAllBytes(file.toPath()), Charset.forName("UTF-8")); } catch (IOException e) { throw new IllegalStateException("Failed to read the following file: " + file.getAbsolutePath()); } } else { throw new IllegalArgumentException("The file is not readable: " + file.getAbsolutePath()); } }
From source file:grakn.core.daemon.executor.Executor.java
/** * Method used to check whether the pid contained in the pid file actually corresponds * to a Grakn(Storage) process./* ww w . j a v a 2s. c o m*/ * * @param pidFile path to pid file * @param className name of Class associated to the given pid (e.g. "grakn.core.server.Grakn") * @return true if PID is associated to the a Grakn process, false otherwise. */ public boolean isAGraknProcess(Path pidFile, String className) { String processPid; if (pidFile.toFile().exists()) { try { processPid = new String(Files.readAllBytes(pidFile), StandardCharsets.UTF_8); if (processPid.trim().isEmpty()) { return false; } Result command = executeAndWait(getGraknPIDArgsCommand(processPid), null); if (command.exitCode() != 0) { return false; } return command.stdout().contains(className); } catch (NumberFormatException | IOException e) { return false; } } return false; }
From source file:com.github.albfernandez.joinpdf.JoinPdf.java
private void addImage(final File file, final Document document, final PdfWriter writer) throws Exception { Image image = Image.getInstance(Files.readAllBytes(file.toPath())); addImage(image, document, writer);//from w w w . j ava 2 s . com }
From source file:grakn.core.distribution.GraknGraqlCommands_WithARunningGraknE2E.java
/** * make sure Grakn is properly writing logs inside grakn.log file *///from ww w . j a v a 2 s . c o m @Test public void logMessagesArePrintedInLogFile() throws IOException { Path logsPath = getLogsPath(); Path graknLogFilePath = logsPath.resolve("grakn.log"); String logsString = new String(Files.readAllBytes(graknLogFilePath), StandardCharsets.UTF_8); assertThat(logsString, containsString("Grakn started")); }
From source file:org.trustedanalytics.h2oscoringengine.publisher.steps.AppBitsUploadingStep.java
private ByteArrayResource prepareData(Path dataPath) throws IOException { return new ByteArrayResource(Files.readAllBytes(dataPath)) { @Override/*from w w w. ja v a 2s . co m*/ public String getFilename() { return dataPath.getFileName().toString(); } }; }