Example usage for java.nio.file Files readAllBytes

List of usage examples for java.nio.file Files readAllBytes

Introduction

In this page you can find the example usage for java.nio.file Files readAllBytes.

Prototype

public static byte[] readAllBytes(Path path) throws IOException 

Source Link

Document

Reads all the bytes from a file.

Usage

From source file:com.hubcap.inputs.CLIOptionBuilder.java

private static void buildAvailableOptions() {

    availableOptions = new Options();

    Path p = Paths.get("resources/help", "help.txt");
    String helpStr = "help is on the way...check the readme!";

    if (helpContent == null) {
        try {//from ww  w  .  j av  a 2s. c  o  m
            helpContent = new String(Files.readAllBytes(p));
        } catch (IOException ex) {
            helpContent = helpStr;
            System.err.println("Help File Couldn't be loaded! " + p.toString());

            if (ProcessModel.instance().getVerbose())
                ErrorUtils.printStackTrace(ex);
        }
    }

    availableOptions.addOption("h", "help", false, helpContent);
    availableOptions.addOption("v", "verbose", false, "Be verbose");
    availableOptions.addOption("q", "quiet", false, "Be quiet (cancels verbose)");
    availableOptions.addOption("r", "no-repl", false, "DONT fallback to repl mode");
    availableOptions.addOption("f", "file", true, "Write results to this file (instead of the default)");
    availableOptions.addOption("m", "mode", true,
            "Set the task mode, valid settings are 'search', 'deepsearch', 'watch', 'debug', default is 'search'");

    Option property = Option.builder("D").hasArgs().valueSeparator('=').build();
    availableOptions.addOption(property);
}

From source file:io.github.casnix.spawnerdropper.Config.java

public static int GetCreeperChance() {
    try {// ww w .  j  ava2s .c  o m
        // Read entire ./SpawnerDropper/SpawnerDropperConfig.json into a string
        //         System.out.println("[SD DEBUG] 7");
        String configTable = new String(
                Files.readAllBytes(Paths.get("./plugins/SpawnerDropper/SpawnerDropperConfig.json")));

        // get the value of JSON->{spawnerType}
        //      System.out.println("[SD DEBUG] 8");
        JSONParser parser = new JSONParser();

        //   System.out.println("[SD DEBUG] 9");
        Object obj = parser.parse(configTable);

        //System.out.println("[SD DEBUG] 10");
        JSONObject jsonObj = (JSONObject) obj;

        //         System.out.println("[SD DEBUG] 11");
        String chance = (String) jsonObj.get("creeperpercent");
        //      System.out.println("[SD DEBUG] 12");
        return Integer.valueOf(chance);
    } catch (ParseException e) {
        Bukkit.getLogger().warning("[SpawnerDropper] Caught ParseException in GetCreeperChance(void)");
        e.printStackTrace();

        return -1;
    } catch (FileNotFoundException e) {
        Bukkit.getLogger()
                .warning("[SpawnerDropper] Could not find ./plugins/SpawnerDropper/SpawnerDropperConfig.json");
        e.printStackTrace();

        return -1;
    } catch (IOException e) {
        Bukkit.getLogger().warning("[SpawnerDropper] Caught IOException in GetCreeperChance(void)");
        e.printStackTrace();

        return -1;
    } catch (NumberFormatException e) {
        Bukkit.getLogger().warning("[SpawnerDropper] Caught NumberFormatException in GetCreeperChance(void)");
        e.printStackTrace();

        return -1;
    }
}

From source file:guru.bubl.service.resources.vertex.VertexImageResource.java

@GET
@Produces("application/octet-stream")
@Path("/{imageId}/big")
public byte[] getBig(@PathParam("imageId") String imageId) {
    try {/*from  w  ww .  jav a2 s .  c o  m*/
        return Files.readAllBytes(Paths.get(IMAGES_FOLDER_PATH + "/" + imageId + "_big"));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.sastix.cms.server.services.cache.CacheFileUtilsServiceTest.java

@Test
public void downloadLocalResourceTest() throws IOException, URISyntaxException {
    //from local storage
    URL localFile = getClass().getClassLoader().getResource("./logo.png");
    byte[] bytesFound = cacheFileUtilsService.downloadResource(localFile);
    byte[] expected = Files.readAllBytes(Paths.get(localFile.getFile()));
    Assert.assertArrayEquals(expected, bytesFound);

}

From source file:integration.util.mongodb.BsonReader.java

protected List<DBObject> readBsonFile(String filename) {
    Path filePath = Paths.get(filename);
    List<DBObject> dataset = new ArrayList<>();

    try {/*from   ww w .j  a va  2 s. com*/
        ByteArrayInputStream fileBytes = new ByteArrayInputStream(Files.readAllBytes(filePath));
        BSONDecoder decoder = new BasicBSONDecoder();
        BSONObject obj;

        while ((obj = decoder.readObject(fileBytes)) != null) {
            final DBObject mongoDocument = new BasicDBObject(obj.toMap());
            dataset.add(mongoDocument);
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        throw new RuntimeException("Can not open BSON input file.", e);
    } catch (JsonProcessingException e) {
        e.printStackTrace();
        throw new RuntimeException("Can not parse BSON data.", e);
    } catch (IOException e) {
        //EOF
    }

    return dataset;
}

From source file:org.createnet.raptor.utils.TestUtils.java

protected JsonNode loadData(String filename) {

    try {/*from  w w w .j a va2 s . c o m*/
        String filepath = filename + ".json";
        URL res = getClass().getClassLoader().getResource(filepath);

        if (res == null) {
            throw new IOException("Cannot load " + filepath);
        }

        String strpath = res.getPath();

        Path path = Paths.get(strpath);
        byte[] content = Files.readAllBytes(path);

        return mapper.readTree(content);
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:br.unb.cic.bionimbuz.services.storage.bucket.methods.CloudMethodsAmazonGoogle.java

@Override
public void StorageAuth(StorageProvider sp) throws Exception {

    switch (sp) {

    case AMAZON: {
        // InputStream is = null;
        // is = new FileInputStream(keyAmazon);
        // PropertiesCredentials credentials = new PropertiesCredentials(is);
        final byte[] encoded = Files.readAllBytes(Paths.get(keyAmazon));
        final String fileContent = new String(encoded, Charset.defaultCharset());
        System.out.println("AuthString: " + fileContent);
        String accessKeyID, accessKey;
        final int delimiter = fileContent.indexOf(':');
        accessKeyID = fileContent.substring(0, delimiter);
        accessKey = fileContent.substring(delimiter + 1);
        final AWSCredentials credentials = new BasicAWSCredentials(accessKeyID, accessKey);
        s3client = new AmazonS3Client(credentials);

        break;// w w w.j ava  2s .  c om
    }
    case GOOGLE: {

        final String command = gcloudFolder + "gcloud auth activate-service-account --key-file=" + keyGoogle;
        ExecCommand(command);

        break;
    }
    default: {
        throw new Exception("Provedor incorreto!");
    }
    }
}

From source file:com.diffplug.gradle.GradleIntegrationTest.java

protected String read(String path) throws IOException {
    Path target = folder.getRoot().toPath().resolve(path);
    String content = new String(Files.readAllBytes(target), StandardCharsets.UTF_8);
    return FileMisc.toUnixNewline(content);
}

From source file:by.creepid.docsreporter.converter.images.ImageConverterImplTest.java

@Before
public void setUp() {
    try {
        photo = Files.readAllBytes(path);
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:io.warp10.worf.WorfTemplate.java

public WorfTemplate(Properties config, String templateFilePath) throws WorfException {
    try {/* w w w  .  j  ava 2s.c o m*/
        this.config = config;

        if (isTemplate(config)) {
            config.remove("worf.template");
        }

        // load template file
        Path templatePath = Paths.get(templateFilePath);
        Charset charset = StandardCharsets.UTF_8;

        content = new String(Files.readAllBytes(templatePath), charset);
    } catch (Exception exp) {
        throw new WorfException("Unable to load template cause=" + exp.getMessage());
    }
}