Search in sources :

Example 51 with FileInputStream

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;
}
Also used : ServletException(javax.servlet.ServletException) FileInputStream(java.io.FileInputStream) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) Template(groovy.text.Template)

Example 52 with FileInputStream

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);
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) FileInputStream(java.io.FileInputStream)

Example 53 with FileInputStream

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();
    }
}
Also used : Configuration(org.apache.flink.configuration.Configuration) IOException(java.io.IOException) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream)

Example 54 with FileInputStream

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;
}
Also used : SSLContext(javax.net.ssl.SSLContext) KeyStore(java.security.KeyStore) File(java.io.File) FileInputStream(java.io.FileInputStream) KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

Example 55 with FileInputStream

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());
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileInputStream(java.io.FileInputStream)

Aggregations

FileInputStream (java.io.FileInputStream)5931 File (java.io.File)2701 IOException (java.io.IOException)2699 InputStream (java.io.InputStream)1514 FileOutputStream (java.io.FileOutputStream)922 FileNotFoundException (java.io.FileNotFoundException)876 BufferedInputStream (java.io.BufferedInputStream)744 InputStreamReader (java.io.InputStreamReader)680 BufferedReader (java.io.BufferedReader)558 Properties (java.util.Properties)552 Test (org.junit.Test)543 ArrayList (java.util.ArrayList)320 DataInputStream (java.io.DataInputStream)288 OutputStream (java.io.OutputStream)273 ByteArrayInputStream (java.io.ByteArrayInputStream)238 ZipEntry (java.util.zip.ZipEntry)221 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)200 HashMap (java.util.HashMap)195 XmlPullParser (org.xmlpull.v1.XmlPullParser)184 ByteArrayOutputStream (java.io.ByteArrayOutputStream)177