use of java.io.FileInputStream in project groovy by apache.
the class TemplateServlet method getTemplate.
/**
* Gets the template created by the underlying engine parsing the request.
*
* <p>
* This method looks up a simple (weak) hash map for an existing template
* object that matches the source file. If the source file didn't change in
* length and its last modified stamp hasn't changed compared to a precompiled
* template object, this template is used. Otherwise, there is no or an
* invalid template object cache entry, a new one is created by the underlying
* template engine. This new instance is put to the cache for consecutive
* calls.
*
* @return The template that will produce the response text.
* @param file The file containing the template source.
* @throws ServletException If the request specified an invalid template source file
*/
protected Template getTemplate(File file) throws ServletException {
String key = file.getAbsolutePath();
Template template = findCachedTemplate(key, file);
//
if (template == null) {
try {
template = createAndStoreTemplate(key, new FileInputStream(file), file);
} catch (Exception e) {
throw new ServletException("Creation of template failed: " + e, e);
}
}
return template;
}
use of java.io.FileInputStream in project hadoop by apache.
the class Credentials method readTokenStorageFile.
/**
* Convenience method for reading a token storage file and loading its Tokens.
* @param filename
* @param conf
* @throws IOException
*/
public static Credentials readTokenStorageFile(File filename, Configuration conf) throws IOException {
DataInputStream in = null;
Credentials credentials = new Credentials();
try {
in = new DataInputStream(new BufferedInputStream(new FileInputStream(filename)));
credentials.readTokenStorageStream(in);
return credentials;
} catch (IOException ioe) {
throw new IOException("Exception reading " + filename, ioe);
} finally {
IOUtils.cleanup(LOG, in);
}
}
use of java.io.FileInputStream in project flink by apache.
the class AbstractParameterToolTest method validate.
protected void validate(ParameterTool parameter) {
ClosureCleaner.ensureSerializable(parameter);
Assert.assertEquals("myInput", parameter.getRequired("input"));
Assert.assertEquals("myDefaultValue", parameter.get("output", "myDefaultValue"));
Assert.assertEquals(null, parameter.get("whatever"));
Assert.assertEquals(15L, parameter.getLong("expectedCount", -1L));
Assert.assertTrue(parameter.getBoolean("thisIsUseful", true));
Assert.assertEquals(42, parameter.getByte("myDefaultByte", (byte) 42));
Assert.assertEquals(42, parameter.getShort("myDefaultShort", (short) 42));
Configuration config = parameter.getConfiguration();
Assert.assertEquals(15L, config.getLong("expectedCount", -1L));
Properties props = parameter.getProperties();
Assert.assertEquals("myInput", props.getProperty("input"));
props = null;
// -------- test the default file creation ------------
try {
String pathToFile = tmp.newFile().getAbsolutePath();
parameter.createPropertiesFile(pathToFile);
Properties defaultProps = new Properties();
try (FileInputStream fis = new FileInputStream(pathToFile)) {
defaultProps.load(fis);
}
Assert.assertEquals("myDefaultValue", defaultProps.get("output"));
Assert.assertEquals("-1", defaultProps.get("expectedCount"));
Assert.assertTrue(defaultProps.containsKey("input"));
} catch (IOException e) {
Assert.fail(e.getMessage());
e.printStackTrace();
}
}
use of java.io.FileInputStream in project flink by apache.
the class SSLUtils method createSSLServerContext.
/**
* Creates the SSL Context for the server if SSL is configured
*
* @param sslConfig
* The application configuration
* @return The SSLContext object which can be used by the ssl transport server
* Returns null if SSL is disabled
* @throws Exception
* Thrown if there is any misconfiguration
*/
public static SSLContext createSSLServerContext(Configuration sslConfig) throws Exception {
Preconditions.checkNotNull(sslConfig);
SSLContext serverSSLContext = null;
if (getSSLEnabled(sslConfig)) {
LOG.debug("Creating server SSL context from configuration");
String keystoreFilePath = sslConfig.getString(ConfigConstants.SECURITY_SSL_KEYSTORE, null);
String keystorePassword = sslConfig.getString(ConfigConstants.SECURITY_SSL_KEYSTORE_PASSWORD, null);
String certPassword = sslConfig.getString(ConfigConstants.SECURITY_SSL_KEY_PASSWORD, null);
String sslProtocolVersion = sslConfig.getString(ConfigConstants.SECURITY_SSL_PROTOCOL, ConfigConstants.DEFAULT_SECURITY_SSL_PROTOCOL);
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
FileInputStream keyStoreFile = null;
try {
keyStoreFile = new FileInputStream(new File(keystoreFilePath));
ks.load(keyStoreFile, keystorePassword.toCharArray());
} finally {
if (keyStoreFile != null) {
keyStoreFile.close();
}
}
// Set up key manager factory to use the server key store
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(ks, certPassword.toCharArray());
// Initialize the SSLContext
serverSSLContext = SSLContext.getInstance(sslProtocolVersion);
serverSSLContext.init(kmf.getKeyManagers(), null, null);
}
return serverSSLContext;
}
use of java.io.FileInputStream in project hadoop by apache.
the class MiniKdc method resetDefaultRealm.
private void resetDefaultRealm() throws IOException {
InputStream templateResource = new FileInputStream(getKrb5conf().getAbsolutePath());
String content = IOUtil.readInput(templateResource);
content = content.replaceAll("default_realm = .*\n", "default_realm = " + getRealm() + "\n");
IOUtil.writeFile(content, getKrb5conf());
}
Aggregations