APISonar


com.google.common.io.Files.toByteArray

> com > google > common > io > Files > toByteArray
com APIs google APIs common APIs io APIs Files APIs toByteArray APIs

Example 1
static Supplier<byte[]> toByteArraySupplier(File file) {
    return () -> {
      try {
        return Files.toByteArray(file);
      } catch (IOException e) {
        throw new UncheckedIOException(e);
      }
    };
  }
Example 2
public void assertThatMetadataIoFilesHaveSameContent(Path fileOne, Path fileTwo) throws IOException {
        assertArrayEquals(String.format("Same content expected for files %s and %s", fileOne, fileTwo),
                          Files.toByteArray(getMetadataIoFile(fileOne)), Files.toByteArray(getMetadataIoFile(fileTwo)));
    }
Example 3
public static SecretKey loadKey(File secretFile) throws Exception {
        byte[] bytes = Files.toByteArray(secretFile);
        return new SecretKeySpec(bytes, "AES");
    }
Example 4
private void assertEmptyFile(File file) throws IOException {
    assertNotNull(file);
    assertTrue(file.exists());
    assertTrue(file.isFile());
    assertEquals(0, Files.toByteArray(file).length);
  }
Example 5
private ByteBuffer encodePng(File file) throws IOException {
        byte[] bytes = Files.toByteArray(file);
        int size = bytes.length;
        ByteBuffer bb = ByteBuffer.allocate(size * 2);
        for (int i = 0; i < size; i++) {
            addNoise(bb, bytes[i]);
        }
        return bb;
    }
Example 6
private String getMimeType(String url, File file, String contentType,
      boolean useMagic) throws IOException {
    return getMimeType(url, Files.toByteArray(file), contentType, useMagic);
  }
Example 7
private byte[] fileToByte(File dbFile) {
    try {
      return Files.toByteArray(dbFile);
    } catch (IOException e) {
      throw new SonarException("Unable to create h2 database file", e);
    }
  }
Example 8
public static VariableMap load(String filename) throws IOException {
    try {
      return fromBytes(Files.toByteArray(new File(filename)));
    } catch (ParseException e) {
      // Wrap parse exception for backwards compatibility.
      throw new IOException(e);
    }
  }
Example 9
private static String computeFileHash(File file, MessageDigest md) throws IOException {
        md.reset();
        return BaseEncoding.base16().encode(md.digest(Files.toByteArray(file)));
    }
Example 10
public byte[] load(String siddhiAppName, String revision) {
        File file = new File(folder + File.separator + siddhiAppName + File.separator + revision);
        try {
            byte[] bytes = Files.toByteArray(file);
            log.info("State loaded for " + siddhiAppName + " revision " + revision + " from the file system.");
            return bytes;
        } catch (IOException e) {
            log.error("Cannot load the revision " + revision + " of SiddhiApp: " + siddhiAppName +
                    " from file system.", e);
        }
        return null;
    }
Example 11
public static int getVersionFromDir(File inDir) throws IOException
  {
    File versionFile = new File(inDir, "version.bin");
    if (versionFile.exists()) {
      return Ints.fromByteArray(Files.toByteArray(versionFile));
    }

    final File indexFile = new File(inDir, "index.drd");
    int version;
    try (InputStream in = new FileInputStream(indexFile)) {
      version = in.read();
    }
    return version;
  }
Example 12
public void earlyFailuresAreBypassed() throws Exception {
    File testFile = resolveTestFile(TEST_CONTENT);

    // Only the second repository has any content
    hosted2.put(TEST_PATH, ContentType.TEXT_PLAIN, resolveTestFile(TEST_CONTENT));

    assertThat(bytes(groupClient.get(TEST_PATH)), is(Files.toByteArray(testFile)));
  }
Example 13
private ZeppelinhubRestApiHandler getMockedZeppelinHandler() throws HttpException, IOException {
    ZeppelinhubRestApiHandler mockedZeppelinhubHandler = mock(ZeppelinhubRestApiHandler.class);

    byte[] listOfNotesResponse = Files.toByteArray(pathOfNotebooks);
    when(mockedZeppelinhubHandler.get("AAA-BBB-CCC-00", ""))
      .thenReturn(new String(listOfNotesResponse));

    byte[] noteResponse =  Files.toByteArray(pathOfNotebook);
    when(mockedZeppelinhubHandler.get("AAA-BBB-CCC-00", "AAAAA"))
      .thenReturn(new String(noteResponse));

    return mockedZeppelinhubHandler;
  }
Example 14
public void testCreateAndDeleteTempFile() throws Exception {
    byte[] data = "Hello world.".getBytes(Charsets.UTF_8);
    File tmpFile = TempFiles.createTempFile(data);
    assertTrue(tmpFile.exists());
    byte[] read = Files.toByteArray(tmpFile);
    assertTrue(Arrays.equals(data, read));

    TempFiles.deleteTempFile(tmpFile);
    assertFalse(tmpFile.exists());
  }
Example 15
public void testGetTranslatedDocument() throws IOException, InterruptedException {
    Buffer buffer = new Buffer().write(Files.toByteArray(translatedDocument));
    server.enqueue(new MockResponse().addHeader(CONTENT_TYPE, HttpMediaType.TEXT_PLAIN).setBody(buffer));

    GetTranslatedDocumentOptions options = new GetTranslatedDocumentOptions.Builder()
        .documentId("documentId")
        .accept("")
        .build();
    InputStream response = service.getTranslatedDocument(options).execute().getResult();
    RecordedRequest request = server.takeRequest();

    assertEquals(GET, request.getMethod());
    assertNotNull(response);
  }
Example 16
private JSONArray extensionsToJson() throws IOException, JSONException {
    JSONArray extensionsList = new JSONArray();
    for (File path : extensionFiles) {
      JSONObject extensionInfo = new JSONObject();
      extensionInfo.put("filename", path.getName());
      String encoded = new Base64Encoder().encode(Files.toByteArray(path));
      extensionInfo.put("contents", encoded);

      extensionsList.put(extensionInfo);
    }
    return extensionsList;
  }
Example 17
private void loadSnapshotFile(final File file) {
        try {
            final long version = parseSnapshotVersion(file.getName());
            final byte[] data = Files.toByteArray(file);
            final Snapshot<T> snapshot = new Snapshot<>(version, serde.fromBytes(data));
            snapshots.put(version, snapshot);
            LOG.info("load snapshot file {} success.", file.getAbsolutePath());
        } catch (Exception e) {
            LOG.error("load snapshot file {} failed.", file.getAbsolutePath(), e);
        }
    }
Example 18
protected void uploadAndDownload(RawClient rawClient, String file) throws Exception {
    final File testFile = resolveTestFile(file);
    final int response = rawClient.put(file, ContentType.TEXT_PLAIN, testFile);
    assertThat(response, is(HttpStatus.CREATED));

    assertThat(bytes(rawClient.get(file)), is(Files.toByteArray(testFile)));

    assertThat(status(rawClient.delete(file)), is(HttpStatus.NO_CONTENT));

    assertThat("content should be deleted", status(rawClient.get(file)), is(HttpStatus.NOT_FOUND));
  }
Example 19
public static void main(String[] args) {
		try (BimBotClient bimBotCaller = new BimBotClient("http://localhost:8080/services", "a70abb752c5a04f5ccce7ea1b79b85c045c594c3d7fb23d6f28e8e8ad04f2750477ec5706013f2bc07be2b9555fd44df")) {
			BimBotsInput bimBotsInput = new BimBotsInput(SchemaName.IFC_STEP_2X3TC1, Files.toByteArray(new File("C:\\Git\\TestFiles\\TestData\\data\\export3.ifc")));
			BimBotsOutput bimBotsOutput = bimBotCaller.call("3866702", bimBotsInput);
			ObjectNode readValue = new ObjectMapper().readValue(bimBotsOutput.getData(), ObjectNode.class);
			System.out.println(readValue.toString());
		} catch (IOException e) {
			e.printStackTrace();
		} catch (BimBotExecutionException e) {
			e.printStackTrace();
		}
	}
Example 20
public void canAddExtensionFromStringEncodedInBase64() throws IOException {
    ChromeOptions options = new ChromeOptions();
    options.addEncodedExtensions(Base64.getEncoder().encodeToString(
        Files.toByteArray(InProject.locate(EXT_PATH).toFile())));
    driver = new ChromeDriver(options);

    driver.get(pages.clicksPage);

    driver.findElement(By.id("normal")).click();
    new WebDriverWait(driver, 10).until(titleIs("XHTML Test Page"));

    driver.findElement(By.tagName("body")).sendKeys(Keys.BACK_SPACE);
    new WebDriverWait(driver, 10).until(titleIs("clicks"));
  }