/** * Reads all characters from a URL into a {@link String}, using the given character set. * * @param url the URL to read from * @param charset the charset used to decode the input stream; see {@link Charsets} for helpful * predefined constants * @return a string containing all the characters from the URL * @throws IOException if an I/O error occurs. */ public static String toString(URL url, Charset charset) throws IOException { return asCharSource(url, charset).read(); }
/** * Reads all characters from a file into a {@link String}, using the given character set. * * @param file the file to read from * @param charset the charset used to decode the input stream; see {@link StandardCharsets} for * helpful predefined constants * @return a string containing all the characters from the file * @throws IOException if an I/O error occurs * @deprecated Prefer {@code asCharSource(file, charset).read()}. This method is scheduled to be * removed in January 2019. */ @Deprecated public static String toString(File file, Charset charset) throws IOException { return asCharSource(file, charset).read(); }
/** * Reads all characters from a URL into a {@link String}, using the given character set. * * @param url the URL to read from * @param charset the charset used to decode the input stream; see {@link Charsets} for helpful * predefined constants * @return a string containing all the characters from the URL * @throws IOException if an I/O error occurs. */ public static String toString(URL url, Charset charset) throws IOException { return asCharSource(url, charset).read(); }
/** * Reads all characters from a file into a {@link String}, using the given character set. * * @param file the file to read from * @param charset the charset used to decode the input stream; see {@link StandardCharsets} for * helpful predefined constants * @return a string containing all the characters from the file * @throws IOException if an I/O error occurs * @deprecated Prefer {@code asCharSource(file, charset).read()}. This method is scheduled to be * removed in January 2019. */ @Deprecated public static String toString(File file, Charset charset) throws IOException { return asCharSource(file, charset).read(); }
/** * Reads all characters from a URL into a {@link String}, using the given character set. * * @param url the URL to read from * @param charset the charset used to decode the input stream; see {@link Charsets} for helpful * predefined constants * @return a string containing all the characters from the URL * @throws IOException if an I/O error occurs. */ public static String toString(URL url, Charset charset) throws IOException { return asCharSource(url, charset).read(); }
/** * Reads all characters from a file into a {@link String}, using the given character set. * * @param file the file to read from * @param charset the charset used to decode the input stream; see {@link StandardCharsets} for * helpful predefined constants * @return a string containing all the characters from the file * @throws IOException if an I/O error occurs * @deprecated Prefer {@code asCharSource(file, charset).read()}. This method is scheduled to be * removed in January 2019. */ @Deprecated public static String toString(File file, Charset charset) throws IOException { return asCharSource(file, charset).read(); }
private ImmutableSortedMap<String, ImmutableList<String>> readMap(final String mapPath) { String fileContent; String actualPath = mapPath; try { if (Strings.isNullOrEmpty(mapPath)) { actualPath = this.getClass().getClassLoader().getResource("defaultWhiteListMap.json").getFile(); LOGGER.info("using default whiteList map located at [%s]", actualPath); InputStream byteContent = this.getClass().getClassLoader().getResourceAsStream("defaultWhiteListMap.json"); fileContent = CharStreams.toString(new InputStreamReader(byteContent, StandardCharsets.UTF_8)); } else { fileContent = Files.asCharSource(new File(mapPath), StandardCharsets.UTF_8).read(); } return mapper.readerFor(new TypeReference<ImmutableSortedMap<String, ImmutableList<String>>>() { }).readValue(fileContent); } catch (IOException e) { throw new ISE(e, "Got an exception while parsing file [%s]", actualPath); } }
private ImmutableSortedMap<String, ImmutableSet<String>> readMap(final String mapPath) { String fileContent; String actualPath = mapPath; try { if (Strings.isNullOrEmpty(mapPath)) { URL resource = this.getClass().getClassLoader().getResource("defaultWhiteListMap.json"); actualPath = resource.getFile(); LOGGER.info("using default whiteList map located at [%s]", actualPath); fileContent = Resources.toString(resource, Charset.defaultCharset()); } else { fileContent = Files.asCharSource(new File(mapPath), Charset.forName("UTF-8")).read(); } return mapper.readerFor(new TypeReference<ImmutableSortedMap<String, ImmutableSet<String>>>() { }).readValue(fileContent); } catch (IOException e) { throw new ISE(e, "Got an exception while parsing file [%s]", actualPath); } } }
public void testRead_toString() throws IOException { String string = source.read(); assertExpectedString(string); }
/** * Format the given input (a Java compilation unit) into the output stream. * * @throws FormatterException if the input cannot be parsed */ public void formatSource(CharSource input, CharSink output) throws FormatterException, IOException { // TODO(cushon): proper support for streaming input/output. Input may // not be feasible (parsing) but output should be easier. output.write(formatSource(input.read())); }
public static final String readFileFromClasspathAsString(String fileName) throws IOException { return Files.asCharSource( new File(SketchAggregationTest.class.getClassLoader().getResource(fileName).getFile()), Charset.forName("UTF-8") ).read(); } }
public static final String readFileFromClasspathAsString(String fileName) throws IOException { return Files.asCharSource( new File(SketchAggregationTest.class.getClassLoader().getResource(fileName).getFile()), Charset.forName("UTF-8") ).read(); } }
public static final String readFileFromClasspathAsString(String fileName) throws IOException { return Files.asCharSource( new File(OldApiSketchAggregationTest.class.getClassLoader().getResource(fileName).getFile()), Charset.forName("UTF-8") ).read(); } }
/** * Returns a new TrustSource containing the same trusted CAs as this TrustSource, plus zero or more CAs contained in * the PEM-encoded File. The File may contain multiple certificates and may contain comments or other non-PEM-encoded * text, as long as the PEM-encoded certificates are delimited by appropriate BEGIN_CERTIFICATE and END_CERTIFICATE * text blocks. The file may contain UTF-8 characters, but the PEM-encoded certificate data itself must be US-ASCII. * * @param trustedCAPemFile File containing PEM-encoded certificates * @return a new TrustSource containing this TrustSource's trusted CAs plus the CAs in the specified String */ public TrustSource add(File trustedCAPemFile) { if (trustedCAPemFile == null) { throw new IllegalArgumentException("Trusted CA file cannot be null"); } String pemFileContents; try { pemFileContents = Files.asCharSource(trustedCAPemFile, StandardCharsets.UTF_8).read(); } catch (IOException e) { throw new UncheckedIOException("Unable to read file containing PEM-encoded trusted CAs: " + trustedCAPemFile.getAbsolutePath(), e); } return add(pemFileContents); }
private static LoadedKey loadKeyFile(File file) { if (!file.canRead()) { throw new SignatureException("Unknown signing key ID"); } // try to load the key as a PEM encoded public key try { return new LoadedKey(PemReader.loadPublicKey(file)); } catch (Exception ignored) { } // try to load the key as a base64 encoded HMAC key try { String base64Key = asCharSource(file, US_ASCII).read(); byte[] rawKey = getMimeDecoder().decode(base64Key.getBytes(US_ASCII)); return new LoadedKey(rawKey); } catch (IOException ignored) { } throw new SignatureException("Unknown signing key id"); }
@BeforeClass public void setup() throws Exception { Logging.initialize(); URL resource = getClass().getClassLoader().getResource("33.privateKey"); assertNotNull(resource, "key directory not found"); File keyDir = new File(resource.getFile()).getAbsoluteFile().getParentFile(); defaultKey = getMimeDecoder().decode(asCharSource(new File(keyDir, "default-key.key"), US_ASCII).read().getBytes(US_ASCII)); hmac222 = getMimeDecoder().decode(asCharSource(new File(keyDir, "222.key"), US_ASCII).read().getBytes(US_ASCII)); privateKey33 = PemReader.loadPrivateKey(new File(keyDir, "33.privateKey"), Optional.empty()); server = new TestingPrestoServer( true, ImmutableMap.<String, String>builder() .put("http-server.authentication.type", "JWT") .put("http.authentication.jwt.key-file", new File(keyDir, "${KID}.key").toString()) .put("http-server.https.enabled", "true") .put("http-server.https.keystore.path", getResource("localhost.keystore").getPath()) .put("http-server.https.keystore.key", "changeit") .build(), null, null, new SqlParserOptions(), ImmutableList.of()); server.installPlugin(new TpchPlugin()); server.createCatalog(TEST_CATALOG, "tpch"); waitForNodeRefresh(server); }
public void testConcat() throws IOException { CharSource c1 = CharSource.wrap("abc"); CharSource c2 = CharSource.wrap(""); CharSource c3 = CharSource.wrap("de"); String expected = "abcde"; assertEquals(expected, CharSource.concat(ImmutableList.of(c1, c2, c3)).read()); assertEquals(expected, CharSource.concat(c1, c2, c3).read()); assertEquals(expected, CharSource.concat(ImmutableList.of(c1, c2, c3).iterator()).read()); assertFalse(CharSource.concat(c1, c2, c3).isEmpty()); CharSource emptyConcat = CharSource.concat(CharSource.empty(), CharSource.empty()); assertTrue(emptyConcat.isEmpty()); }
assertEquals(json, actual.read()); assertEquals(json, actual.read()); assertEquals(json, actual.read()); assertEquals(json, actual.read()); assertEquals("{\"abc\b\f\n\r\t\\\\u0001\":\"efg\"}", actual.read()); assertEquals("{\"12xY\":\"efg\"}", actual.read()); CharSource actual = plugin.invalidEscapeStringFunction(SKIP).apply(json); assertEquals("{\"\":\"b\"}", actual.read()); assertEquals("{\"\":\"b\"}\n", actual.read()); assertEquals(json, actual.read()); assertEquals("{\"abc\b\f\n\r\t\\\\u0001\":\"efg\"}", actual.read()); assertEquals("{\"u000x\":\"efg\"}", actual.read()); assertEquals("{\"a\":\"b\"}", actual.read()); assertEquals("{\"\":\"b\"}\n", actual.read());
if (credentialFile.exists()) { credential = Files.asCharSource(credentialFile, StandardCharsets.UTF_8).read();
@Override public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { if (data.isPresent()) { return data.get().asCharSource(Charset.defaultCharset()).read(); } else { throw new FileNotFoundException(); } }