/** * 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(); }
/** * Copies all characters from a file to an appendable object, using the given character set. * * @param from the source file * @param charset the charset used to decode the input stream; see {@link StandardCharsets} for * helpful predefined constants * @param to the appendable object * @throws IOException if an I/O error occurs * @deprecated Prefer {@code asCharSource(from, charset).copyTo(to)}. This method is scheduled to * be removed in January 2019. */ @Deprecated public static void copy(File from, Charset charset, Appendable to) throws IOException { asCharSource(from, charset).copyTo(to); }
/** * Reads the first line from a file. The line does not include line-termination characters, but * does include other leading and trailing whitespace. * * @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 the first line, or null if the file is empty * @throws IOException if an I/O error occurs * @deprecated Prefer {@code asCharSource(file, charset).readFirstLine()}. This method is * scheduled to be removed in January 2019. */ @Deprecated public static String readFirstLine(File file, Charset charset) throws IOException { return asCharSource(file, charset).readFirstLine(); }
return asCharSource(file, charset) .readLines( new LineProcessor<List<String>>() {
/** * Copies all characters from a file to an appendable object, using the given character set. * * @param from the source file * @param charset the charset used to decode the input stream; see {@link StandardCharsets} for * helpful predefined constants * @param to the appendable object * @throws IOException if an I/O error occurs * @deprecated Prefer {@code asCharSource(from, charset).copyTo(to)}. This method is scheduled to * be removed in January 2019. */ @Deprecated public static void copy(File from, Charset charset, Appendable to) throws IOException { asCharSource(from, charset).copyTo(to); }
/** * 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 the first line from a file. The line does not include line-termination characters, but * does include other leading and trailing whitespace. * * @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 the first line, or null if the file is empty * @throws IOException if an I/O error occurs * @deprecated Prefer {@code asCharSource(file, charset).readFirstLine()}. This method is * scheduled to be removed in January 2019. */ @Deprecated public static String readFirstLine(File file, Charset charset) throws IOException { return asCharSource(file, charset).readFirstLine(); }
/** * Streams lines from a {@link File}, stopping when our callback returns false, or we have read * all of the lines. * * @param file the file to read from * @param charset the charset used to decode the input stream; see {@link StandardCharsets} for * helpful predefined constants * @param callback the {@link LineProcessor} to use to handle the lines * @return the output of processing the lines * @throws IOException if an I/O error occurs * @deprecated Prefer {@code asCharSource(file, charset).readLines(callback)}. This method is * scheduled to be removed in January 2019. */ @Deprecated @CanIgnoreReturnValue // some processors won't return a useful result public static <T> T readLines(File file, Charset charset, LineProcessor<T> callback) throws IOException { return asCharSource(file, charset).readLines(callback); }
private static String getActiveGoogleCloudConfig(File configDir) { String activeGoogleCloudConfig = null; try { activeGoogleCloudConfig = Files.asCharSource(new File(configDir, "active_config"), Charset.defaultCharset()) .readFirstLine(); } catch (IOException ex) { // ignore } // if reading active_config failed or the file is empty we try default return firstNonNull(activeGoogleCloudConfig, "default"); }
/** * Copies all characters from a file to an appendable object, using the given character set. * * @param from the source file * @param charset the charset used to decode the input stream; see {@link StandardCharsets} for * helpful predefined constants * @param to the appendable object * @throws IOException if an I/O error occurs * @deprecated Prefer {@code asCharSource(from, charset).copyTo(to)}. This method is scheduled to * be removed in January 2019. */ @Deprecated public static void copy(File from, Charset charset, Appendable to) throws IOException { asCharSource(from, charset).copyTo(to); }
/** * Reads the first line from a file. The line does not include line-termination characters, but * does include other leading and trailing whitespace. * * @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 the first line, or null if the file is empty * @throws IOException if an I/O error occurs * @deprecated Prefer {@code asCharSource(file, charset).readFirstLine()}. This method is * scheduled to be removed in January 2019. */ @Deprecated public static String readFirstLine(File file, Charset charset) throws IOException { return asCharSource(file, charset).readFirstLine(); }
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); } }
@Override public CharSource createSource(String string) throws IOException { checkNotNull(string); File file = createFile(); Writer writer = new OutputStreamWriter(new FileOutputStream(file), Charsets.UTF_8); try { writer.write(string); } finally { writer.close(); } return Files.asCharSource(file, Charsets.UTF_8); }
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); } } }
/** * Streams lines from a {@link File}, stopping when our callback returns false, or we have read * all of the lines. * * @param file the file to read from * @param charset the charset used to decode the input stream; see {@link StandardCharsets} for * helpful predefined constants * @param callback the {@link LineProcessor} to use to handle the lines * @return the output of processing the lines * @throws IOException if an I/O error occurs * @deprecated Prefer {@code asCharSource(file, charset).readLines(callback)}. This method is * scheduled to be removed in January 2019. */ @Deprecated @CanIgnoreReturnValue // some processors won't return a useful result public static <T> T readLines(File file, Charset charset, LineProcessor<T> callback) throws IOException { return asCharSource(file, charset).readLines(callback); }
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(); } }
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); }