Java Examples for java.nio.file.Files.readAllBytes
The following java examples will help you to understand the usage of java.nio.file.Files.readAllBytes. These source code samples are taken from different open source projects.
Example 1
| Project: cognitionis-nlp-libraries-master File: TokenizerTest.java View source code |
/**
* Test of tokenize method, of class Tokenizer_PTB_Rulebased.
*/
@Test
public void testTokenize_File() throws Exception {
System.out.println("tokenize");
//java.net.URL url = this.class.getResource("test/resources/tokenizer/test-input.txt");
//File f=FileUtils.toFile(this.getClass().getResource("/tokenizer/test-input.txt.tokenized"));
File f_in = new File(this.getClass().getResource("/tokenizer/test-input.txt").toURI());
File f_out = new File(this.getClass().getResource("/tokenizer/test-input.txt.tokenized").toURI());
String expResultString = new String(java.nio.file.Files.readAllBytes(f_out.toPath()), "UTF-8");
String inputString = new String(java.nio.file.Files.readAllBytes(f_in.toPath()), "UTF-8");
// tokenize without sentence splitting
Tokenizer_PTB_Rulebased instance = new Tokenizer_PTB_Rulebased(false);
String result = instance.tokenize(inputString);
assertEquals(expResultString, result);
//assertArrayEquals
}Example 2
| Project: Aspose_Pdf_Java-master File: DisableFilesCompressionWhenAddingAsEmbeddedResources.java View source code |
public static void main(String[] args) throws Exception {
// get reference of source/input file
java.nio.file.Path path = java.nio.file.Paths.get("input.pdf");
// read all the contents from source file into ByteArray
byte[] data = java.nio.file.Files.readAllBytes(path);
// create an instance of Stream object from ByteArray contents
InputStream is = new ByteArrayInputStream(data);
// Instantiate Document object from stream instance
Document pdfDocument = new Document(is);
// setup new file to be added as attachment
FileSpecification fileSpecification = new FileSpecification("test.txt", "Sample text file");
// Specify Encoding property setting it to FileEncoding.None
fileSpecification.setEncoding(FileEncoding.None);
// add attachment to document's attachment collection
pdfDocument.getEmbeddedFiles().add(fileSpecification);
// save new output
pdfDocument.save("output.pdf");
}Example 3
| Project: javaee7-samples-master File: SchemaGenScriptsTest.java View source code |
@Test
@RunAsClient
public void testSchemaGenIndex() throws Exception {
Path create = get("target", "create-script.sql");
Path drop = get("target", "drop-script.sql");
assertTrue(exists(create));
assertTrue(exists(drop));
assertTrue(new String(readAllBytes(create), UTF_8).toLowerCase().contains("create table employee_schema_gen_scripts_generate"));
assertTrue(new String(readAllBytes(drop), UTF_8).toLowerCase().contains("drop table employee_schema_gen_scripts_generate"));
}Example 4
| Project: reactive-ms-example-master File: RestServiceHelper.java View source code |
public static <T> Mono<T> getMonoFromJsonPath(final String jsonPath, final Class<T> type) {
try {
final URL url = RestServiceHelper.class.getResource(jsonPath);
final Path resPath = java.nio.file.Paths.get(url.toURI());
final String json = new String(java.nio.file.Files.readAllBytes(resPath), "UTF8");
return getMonoFromJson(json, type);
} catch (IOExceptionURISyntaxException | e) {
throw new RuntimeException(e);
}
}Example 5
| Project: cmn-project-master File: Tarball.java View source code |
private void archive(Path path, TarArchiveOutputStream output) throws IOException {
if (isDirectory(path)) {
archiveFolder(path, output);
} else {
// must covert path to URI to make it compatible with Linux
TarArchiveEntry entry = new TarArchiveEntry(path.toFile(), basePath.relativize(path.toUri()).getPath());
output.putArchiveEntry(entry);
output.write(readAllBytes(path));
output.closeArchiveEntry();
}
}Example 6
| Project: tempto-master File: FileBasedHiveDataSource.java View source code |
@Override
public String revisionMarker() {
return tableDefinitionDescriptor.getRevisionFile().map( revisionFile -> {
try {
if (revisionMarker == null) {
revisionMarker = new String(readAllBytes(revisionFile));
}
return revisionMarker;
} catch (IOException e) {
throw new IllegalStateException("Could not read revision file: " + tableDefinitionDescriptor.getRevisionFile());
}
}).orElse("");
}Example 7
| Project: presto-master File: AbstractTestBackupStore.java View source code |
@Test
public void testBackupStore() throws Exception {
// backup first file
File file1 = new File(temporary, "file1");
Files.write("hello world", file1, UTF_8);
UUID uuid1 = randomUUID();
assertFalse(store.shardExists(uuid1));
store.backupShard(uuid1, file1);
assertTrue(store.shardExists(uuid1));
// backup second file
File file2 = new File(temporary, "file2");
Files.write("bye bye", file2, UTF_8);
UUID uuid2 = randomUUID();
assertFalse(store.shardExists(uuid2));
store.backupShard(uuid2, file2);
assertTrue(store.shardExists(uuid2));
// verify first file
File restore1 = new File(temporary, "restore1");
store.restoreShard(uuid1, restore1);
assertEquals(readAllBytes(file1.toPath()), readAllBytes(restore1.toPath()));
// verify second file
File restore2 = new File(temporary, "restore2");
store.restoreShard(uuid2, restore2);
assertEquals(readAllBytes(file2.toPath()), readAllBytes(restore2.toPath()));
// verify random UUID does not exist
assertFalse(store.shardExists(randomUUID()));
// delete first file
assertTrue(store.shardExists(uuid1));
assertTrue(store.shardExists(uuid2));
store.deleteShard(uuid1);
store.deleteShard(uuid1);
assertFalse(store.shardExists(uuid1));
assertTrue(store.shardExists(uuid2));
// delete random UUID
store.deleteShard(randomUUID());
}Example 8
| Project: DataGenerator-master File: XSDAdapter.java View source code |
private List<String> generatePOJO(Path output, Path input) throws Exception {
String exec = String.format("/usr/bin/xjc -d %s %s", output, input);
System.out.println(exec);
Process p = Runtime.getRuntime().exec(exec);
p.waitFor();
Path generated = Paths.get(output.toString() + "/generated");
File[] files = generated.toFile().listFiles();
List<String> sourceFiles = Arrays.stream(files).map( f -> f.toString()).collect(Collectors.toList());
return sourceFiles.stream().map((String sf) -> {
System.out.println("Source: " + sf);
try {
return new String(java.nio.file.Files.readAllBytes(Paths.get(sf)));
} catch (IOException e) {
e.printStackTrace();
}
return null;
}).collect(Collectors.toList());
}Example 9
| Project: ParallelGit-master File: GfsApplyStashTest.java View source code |
@Test
public void applyStash_theLatestStashedChangesShouldAppearInTheFileSystem() throws IOException {
byte[] expected = someBytes();
writeToGfs("/test_file.txt", expected);
createStash(gfs).execute();
reset(gfs).execute();
Result result = applyStash(gfs).execute();
assertTrue(result.isSuccessful());
assertArrayEquals(expected, readAllBytes(gfs.getPath("/test_file.txt")));
}Example 10
| Project: incubator-streams-master File: StreamsCassandraResourceGeneratorCLITest.java View source code |
@Test
public void testStreamsCassandraResourceGeneratorCLI() throws Exception {
String sourceDirectory = "target/test-classes/activitystreams-schemas";
String targetDirectory = "target/generated-resources/test-cli";
StreamsCassandraResourceGenerator.main(new String[] { sourceDirectory, targetDirectory });
File testOutput = new File(targetDirectory);
Assert.assertNotNull(testOutput);
Assert.assertTrue(testOutput.exists());
Assert.assertTrue(testOutput.isDirectory());
Collection<File> outputCollection = FileUtils.listFiles(testOutput, StreamsCassandraResourceGeneratorTest.cqlFilter, true);
Assert.assertEquals(outputCollection.size(), 1);
Path path = Paths.get(testOutput.getAbsolutePath()).resolve("types.cql");
Assert.assertTrue(path.toFile().exists());
String typesCqlBytes = new String(java.nio.file.Files.readAllBytes(path));
Assert.assertEquals(StringUtils.countMatches(typesCqlBytes, "CREATE TYPE"), 133);
}Example 11
| Project: Wilma-master File: WilmaTestLogDecorator.java View source code |
/**
* Loads the request message, from the filename.
*
* @param filename is the source of the request message
* @throws Exception in any case of error
*/
protected void setOriginalRequestMessageFromFile(final String filename) throws Exception {
if ((!filename.endsWith(".xml")) && (!filename.endsWith(".fis") && (!filename.endsWith(".json")))) {
throw new Exception("Original request message should be an xml, json or fastinfoset file!");
}
File file = new File(filename);
URI uri = file.toURI();
byte[] bytes = java.nio.file.Files.readAllBytes(java.nio.file.Paths.get(uri));
originalRequestMessage = decodeUTF8(bytes);
}