List of usage examples for java.nio.file Files readAllBytes
public static byte[] readAllBytes(Path path) throws IOException
From source file:minij.MiniJCompilerTest.java
@Test public void testCompileExamples() throws IOException { System.out.println("Testing compiler input from file \"" + file.toString() + "\""); Configuration config = new Configuration(new String[] { file.toString() }); config.outputFile = "out" + File.separator + config.outputFile; try {// w w w .j a va2s . c o m compiler.compile(config); String output = compiler.runExecutable(config, 15); if (exceptionClass != null) { fail("The example " + file.toString() + " should have failed with exception " + exceptionClass + ", but was accepted by the compiler."); } byte[] content = Files.readAllBytes(new File("src/test/resources/minij-examples-outputs/working/" + FilenameUtils.getBaseName(file.toString()) + ".txt").toPath()); String expectedOutput = new String(content); if (!output.equals(expectedOutput)) { fail("The example " + file.toString() + " should have printed '" + expectedOutput + "' but printed '" + output + "'"); } } catch (Exception e) { if (exceptionClass == null) { e.printStackTrace(); fail("The example " + file.toString() + " should have been accepted by the compiler but failed: " + e.getMessage()); } if (!exceptionClass.isInstance(e)) { fail("The example " + file.toString() + " should have failed with exception " + exceptionClass + " but with failed with exception " + e.getClass() + ", " + e.getMessage()); } } }
From source file:halive.shootinoutside.common.core.game.map.GameMap.java
private static byte[] loadDefaultTextureSheet() { File f = new File("map/DefaultTileMap.png"); try {//from w w w .jav a2 s. c om return Files.readAllBytes(f.toPath()); } catch (IOException e) { e.printStackTrace(); return null; } }
From source file:it.polimi.diceH2020.launcher.FileService.java
private <T> T getObjectFromPath(Path Path, Class<T> cls) { String serialized;// ww w . j av a 2 s . c o m try { ObjectMapper mapper = new ObjectMapper(); serialized = new String(Files.readAllBytes(Path)); T data = mapper.readValue(serialized, cls); return data; } catch (IOException e) { return null; } }
From source file:de.fatalix.book.importer.CalibriImporter.java
public static void processBooks(Path root, String solrURL, String solrCore, final int batchSize) throws IOException, SolrServerException { final SolrServer solrServer = SolrHandler.createConnection(solrURL, solrCore); final List<BookEntry> bookEntries = new ArrayList<>(); Files.walkFileTree(root, new SimpleFileVisitor<Path>() { @Override/*from w ww .ja v a 2 s .co m*/ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { if (dir.toString().contains("__MACOSX")) { return FileVisitResult.SKIP_SUBTREE; } try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(dir)) { BookEntry bookEntry = new BookEntry().setUploader("admin"); for (Path path : directoryStream) { if (!Files.isDirectory(path)) { if (path.toString().contains(".opf")) { bookEntry = parseOPF(path, bookEntry); } if (path.toString().contains(".mobi")) { bookEntry.setMobi(Files.readAllBytes(path)).setMimeType("MOBI"); } if (path.toString().contains(".epub")) { bookEntry.setEpub(Files.readAllBytes(path)); } if (path.toString().contains(".jpg")) { bookEntry.setCover(Files.readAllBytes(path)); ByteArrayOutputStream output = new ByteArrayOutputStream(); Thumbnails.of(new ByteArrayInputStream(bookEntry.getCover())).size(130, 200) .toOutputStream(output); bookEntry.setThumbnail(output.toByteArray()); bookEntry.setThumbnailGenerated("done"); } } } if (bookEntry.getMobi() != null || bookEntry.getEpub() != null) { bookEntries.add(bookEntry); if (bookEntries.size() > batchSize) { System.out.println("Adding " + bookEntries.size() + " Books..."); try { SolrHandler.addBeans(solrServer, bookEntries); } catch (SolrServerException ex) { System.out.println(ex.getMessage()); ex.printStackTrace(); } bookEntries.clear(); } } } catch (IOException ex) { ex.printStackTrace(); } return super.preVisitDirectory(dir, attrs); } }); }
From source file:io.github.casnix.mcdropshop.util.configsys.Shops.java
public final Shops getFormattedShopList() { try {// w w w. jav a 2s .c o m String configTable = new String(Files.readAllBytes(Paths.get("./plugins/mcDropShop/Shops.json"))); JSONParser parser = new JSONParser(); Object obj = parser.parse(configTable); JSONObject jsonObj = (JSONObject) obj; JSONArray shopList = (JSONArray) jsonObj.get("shopsArray"); String formattedShopList = "List of mcDropShops:\n"; // Make sure that our array isn't empty if (shopList == null) { formattedShopList = "\u00A7e<\u00A7ainternal error\u00A7e>"; } String shopName; String world; String x; String y; String z; String tmp; JSONObject shopObj; //System.out.println("[MDS DBG MSG] shopList.size() = "+shopList.size()); for (int index = 0; index < shopList.size(); index++) { //System.out.println(index); shopObj = (JSONObject) (shopList.get(index)); //System.out.println(shopObj); shopName = (String) shopObj.get("shopName"); //System.out.println(shopName); world = (String) shopObj.get("world"); //System.out.println(world); x = (String) shopObj.get("x"); //System.out.println(x); y = (String) shopObj.get("y"); //System.out.println(y); z = (String) shopObj.get("z"); //System.out.println(z); formattedShopList = formattedShopList + "\u00A7a" + shopName + ": \u00A7e" + world + "," + x + "," + y + "," + z + "\n"; //System.out.println(formattedShopList); } this.returnStack = (Object) formattedShopList; return this; } catch (ParseException e) { Bukkit.getLogger().warning("[mcDropShop] Caught ParseException in getFormattedShopList(void)"); e.printStackTrace(); } catch (FileNotFoundException e) { Bukkit.getLogger().warning("[mcDropShop] Could not find ./plugins/mcDropShop/Shops.json"); e.printStackTrace(); } catch (IOException e) { Bukkit.getLogger().warning("[mcDropShop] Caught IOException in getFormattedShopList(void)"); e.printStackTrace(); } return this; }
From source file:io.github.swagger2markup.extensions.DynamicDocumentExtensionTest.java
@Test public void testSwagger2AsciiDocExtensions() throws IOException, URISyntaxException { //Given//from ww w . java 2 s . co m Path file = Paths .get(DynamicDocumentExtensionTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); Path outputDirectory = Paths.get("build/test/asciidoc/generated"); FileUtils.deleteQuietly(outputDirectory.toFile()); //When Properties properties = new Properties(); properties .load(DynamicDocumentExtensionTest.class.getResourceAsStream("/config/asciidoc/config.properties")); Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder(properties).build(); Swagger2MarkupExtensionRegistry registry = new Swagger2MarkupExtensionRegistryBuilder() //.withDefinitionsDocumentExtension(new DynamicDefinitionsDocumentExtension(Paths.get("src/test/resources/docs/asciidoc/extensions"))) //.withPathsDocumentExtension(new DynamicPathsDocumentExtension(Paths.get("src/test/resources/docs/asciidoc/extensions"))) .build(); Swagger2MarkupConverter.from(file).withConfig(config).withExtensionRegistry(registry).build() .toFolder(outputDirectory); //Then assertThat(new String(Files.readAllBytes(outputDirectory.resolve("paths.adoc")))) .contains("Pet update request extension"); assertThat(new String(Files.readAllBytes(outputDirectory.resolve("definitions.adoc")))) .contains("Pet extension"); }
From source file:org.zalando.stups.swagger.codegen.YamlToJson.java
protected String getYamlFileContentAsJson() throws IOException { String data = ""; if (yamlInputPath.startsWith("http") || yamlInputPath.startsWith("https")) { data = new String(Resources.toByteArray(new URL(yamlInputPath))); } else {// ww w .j a v a 2 s . c o m data = new String(Files.readAllBytes(java.nio.file.Paths.get(new File(yamlInputPath).toURI()))); } ObjectMapper yamlMapper = Yaml.mapper(); JsonNode rootNode = yamlMapper.readTree(data); // must have swagger node set JsonNode swaggerNode = rootNode.get("swagger"); return rootNode.toString(); }
From source file:uk.ac.sanger.npg.picard.AlignmentFilterTest.java
public int compareJSONFiles(String file_one, String file_two) throws FileNotFoundException, IOException { ObjectMapper objectMapper = new ObjectMapper(); byte[] jsonData_one = Files.readAllBytes(Paths.get(file_one)); byte[] jsonData_two = Files.readAllBytes(Paths.get(file_two)); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JSONtest filter_one = objectMapper.readValue(jsonData_one, JSONtest.class); JSONtest filter_two = objectMapper.readValue(jsonData_two, JSONtest.class); assertEquals(filter_one.programCommand, filter_two.programCommand); assertEquals(filter_one.numberAlignments, filter_two.numberAlignments); assertEquals(filter_one.totalReads, filter_two.totalReads); assertEquals(filter_one.readsCountUnaligned, filter_two.readsCountUnaligned); assertArrayEquals(filter_one.readsCountPerRef, filter_two.readsCountPerRef); assertArrayEquals(filter_one.chimericReadsCount, filter_two.chimericReadsCount); assertArrayEquals(filter_one.readsCountByAlignedNumReverse, filter_two.readsCountByAlignedNumReverse); assertArrayEquals(filter_one.readsCountByAlignedNumForward, filter_two.readsCountByAlignedNumForward); return 1;// www . jav a2 s . c om }
From source file:dhr.uploadtomicrobit.FirmwareGenerator.java
public String generateFirmware(File file) { String script;/*www . jav a2 s. c o m*/ try { script = new String(Files.readAllBytes(Paths.get(file.getAbsolutePath()))); return generateFirmware(script); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } }
From source file:com.batchiq.nifi.executescript.samples.BaseScriptTest.java
public String getFileContentsAsString(String path) { try {/*from www . j a v a2 s . c om*/ return new String(Files.readAllBytes(Paths.get(path))); } catch (IOException ioe) { return null; } }