List of usage examples for java.nio.file Files readAllBytes
public static byte[] readAllBytes(Path path) throws IOException
From source file:com.chenshu.compress.CompressOldTest.java
@Setup public void prepare() { try {// w ww.j ava 2 s . c o m data = Files.readAllBytes(Paths.get("./THIRDPARTYLICENSEREADME.txt")); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.ericsson.eiffel.remrem.semantics.schemas.SchemaFile.java
/** * This method is used to modify the Eiffel repo json files content * /* w w w . j a va2 s . c o m*/ * @param jsonFile * -Eiffel repo event json passed as an input parameter * @param eventName * -Event name passed as an input parameter */ public void modify(File jsonFile, String eventName) { try { this.eventName = eventName; byte[] fileBytes = Files.readAllBytes(Paths.get(jsonFile.getAbsolutePath())); String fileContent = new String(fileBytes); JsonObject jsonContent = parser.parse(fileContent).getAsJsonObject(); JsonObject obj = new JsonObject(); isEvent = true; // Added Java Types and ExtendedTypes to the Json Schema addAttributesToJsonSchema(jsonContent, eventName, obj); // Copy the jsonschema content to the file in project directory // (/input/schemas) createNewInputJsonSchema(eventName, obj); } catch (Exception e) { e.printStackTrace(); } }
From source file:ac.ucy.cs.spdx.license.License.java
/** * License constructor that creates a new License based on the license name, * identifier and File containing the License text that are passed as * parameter. You can enter the category of the license but it is optional. * /*from w ww . j a va2s .co m*/ * @param String * @param String * @param File * @param Category */ public License(String licenseName, String identifier, File licenseText, Category... category) { this.setLicenseName(licenseName); this.setIdentifier(identifier); if (category.length != 0) this.setCategory(category[0]); String text = null; try { text = new String(Files.readAllBytes(Paths.get(licenseText.getAbsolutePath()))); } catch (IOException e) { e.printStackTrace(); } this.setLicenseText(WordUtils.wrap(text, 80)); licenses.add(this); }
From source file:com.falcon.orca.data.readers.impl.JsonFileReader.java
public JsonFileReader(final String dataFilePath, final String templateFilePath) throws IOException { if (!StringUtils.isBlank(templateFilePath)) { this.template = Files.readAllBytes(Paths.get(templateFilePath)); } else {/*from w w w . ja v a2 s. c o m*/ this.template = new byte[0]; } DynJsonData dynData = objectMapper.readValue(new File(dataFilePath), DynJsonData.class); dynData.getBodyParams().forEach((k, v) -> { switch (v.getType()) { case USE_ONCE: { LinkedList<Object> data = new LinkedList<>(); data.addAll(v.getValues()); bodyData.put(k, data); bodyVarUseType.put(k, DynVarUseType.USE_ONCE); break; } case USE_MULTIPLE: { ArrayList<Object> data = new ArrayList<>(); data.addAll(v.getValues()); bodyData.put(k, data); bodyVarUseType.put(k, DynVarUseType.USE_MULTIPLE); break; } } }); dynData.getUrlParams().forEach((k, v) -> { switch (v.getType()) { case USE_ONCE: { LinkedList<Object> data = new LinkedList<>(); data.addAll(v.getValues()); urlData.put(k, data); urlVarUseType.put(k, DynVarUseType.USE_ONCE); break; } case USE_MULTIPLE: { ArrayList<Object> data = new ArrayList<>(); data.addAll(v.getValues()); urlData.put(k, data); urlVarUseType.put(k, DynVarUseType.USE_MULTIPLE); break; } } }); generators = dynData.getGenerators(); }
From source file:org.dawnsci.marketplace.controllers.PageController.java
static String parse(Path path) { if (!path.toFile().exists()) { return ""; }/* ww w. j a va2s. c o m*/ StringWriter sw = new StringWriter(); MarkupParser parser = new MarkupParser(); parser.setMarkupLanguage(new MarkdownLanguage()); HtmlDocumentBuilder builder = new HtmlDocumentBuilder(sw); builder.setEmitAsDocument(false); parser.setBuilder(builder); try { parser.parse(new StringReader(new String(Files.readAllBytes(path)))); } catch (IOException e) { e.printStackTrace(); } return sw.toString(); }
From source file:com.local.ask.controller.mail.MailManagerImpl.java
private String getTemplate() { try {/* w w w . java2 s . c o m*/ URL url = getClass().getResource("mail.html"); File file = new File(url.getPath()); byte[] encoded = Files.readAllBytes(Paths.get(file.getAbsolutePath())); return new String(encoded, "UTF-8"); } catch (IOException ex) { Logger.getLogger(MailManagerImpl.class.getName()).log(Level.SEVERE, null, ex); } return ""; }
From source file:ch.ledcom.jpreseed.cli.JPreseed.java
public final void create(JPreseedArguments arguments) throws IOException { try (InputImage image = getSourceImage(arguments); GZIPOutputStream newImage = new GZIPOutputStream( Files.newOutputStream(arguments.getTargetImage()))) { ByteBuffer sysConfigCfg = ByteBuffer.wrap(Files.readAllBytes(arguments.getSysConfigFile())); usbCreator.create(image.getContent(), newImage, sysConfigCfg, arguments.getPreseeds()); }//from www . j av a 2 s . c om }
From source file:com.streamsets.extra.DockerMetadataCache.java
public DockerMetadataCache(String base, String file) { this.basePath = base; this.filename = file; CacheLoader<String, Map> loader = new CacheLoader<String, Map>() { private final ObjectMapper mapper = new ObjectMapper(); @Override//from w w w . ja v a2s.com public Map load(String key) throws Exception { FileSystem fs = FileSystems.getDefault(); Path path = fs.getPath(basePath, key, filename); final String contents = new String(Files.readAllBytes(path), Charset.forName("UTF-8")); return mapper.readValue(contents, HashMap.class); } }; cache = CacheBuilder.newBuilder().expireAfterAccess(10, TimeUnit.MINUTES).maximumSize(1000).build(loader); }
From source file:org.sead.repositories.reference.util.SEADGoogleLogin.java
public static String getAccessToken() { try {// w w w . ja va 2 s .co m refresh_token = new String(Files.readAllBytes(Paths.get("refresh.txt"))); } catch (IOException e1) { } if (refresh_token == null) { getAuthCode(); // Ask user to login via browser System.out.println( "Did not find stored refresh token. Initiating first-time device authorization request.\n"); System.out.println("1) Go to : " + verification_url + " in your browser\n"); System.out.println("2) Type : " + user_code + " in your browser\n"); System.out.println("3) Hit <Return> to continue.\n"); try { System.in.read(); } catch (IOException e) { log.debug("Error getting user response: " + e.getMessage()); } System.out.println("Proceeding"); getTokensFromCode(); if (refresh_token != null) { PrintWriter writer = null; try { writer = new PrintWriter("refresh.txt", "UTF-8"); writer.print(refresh_token); } catch (FileNotFoundException e) { log.error("Could not write refresh.txt: " + e.getMessage()); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (writer != null) { writer.close(); } } } } else { getTokenFromRefreshToken(); } return access_token; }