Search in sources :

Example 1 with FileInputStream

use of java.io.FileInputStream in project jetty.project by eclipse.

the class SslSelectChannelTimeoutTest method init.

@Before
public void init() throws Exception {
    String keystorePath = System.getProperty("basedir", ".") + "/src/test/resources/keystore";
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStorePath(keystorePath);
    sslContextFactory.setKeyStorePassword("storepwd");
    sslContextFactory.setKeyManagerPassword("keypwd");
    sslContextFactory.setTrustStorePath(keystorePath);
    sslContextFactory.setTrustStorePassword("storepwd");
    ServerConnector connector = new ServerConnector(_server, 1, 1, sslContextFactory);
    //250 msec max idle
    connector.setIdleTimeout(MAX_IDLE_TIME);
    startServer(connector);
    KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
    try (InputStream stream = new FileInputStream(keystorePath)) {
        keystore.load(stream, "storepwd".toCharArray());
    }
    TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    trustManagerFactory.init(keystore);
    __sslContext = SSLContext.getInstance("SSL");
    __sslContext.init(null, trustManagerFactory.getTrustManagers(), null);
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) KeyStore(java.security.KeyStore) FileInputStream(java.io.FileInputStream) Before(org.junit.Before)

Example 2 with FileInputStream

use of java.io.FileInputStream in project jetty.project by eclipse.

the class SslUploadTest method test.

@Test
@Ignore
public void test() throws Exception {
    KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
    SslContextFactory ctx = connector.getConnectionFactory(SslConnectionFactory.class).getSslContextFactory();
    try (InputStream stream = new FileInputStream(ctx.getKeyStorePath())) {
        keystore.load(stream, "storepwd".toCharArray());
    }
    TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    trustManagerFactory.init(keystore);
    SSLContext sslContext = SSLContext.getInstance("SSL");
    sslContext.init(null, trustManagerFactory.getTrustManagers(), null);
    final SSLSocket socket = (SSLSocket) sslContext.getSocketFactory().createSocket("localhost", connector.getLocalPort());
    // Simulate async close
    /*
        new Thread()
        {
            @Override
            public void run()
            {
                try
                {
                    sleep(100);
                    socket.close();
                }
                catch (IOException x)
                {
                    x.printStackTrace();
                }
                catch (InterruptedException x)
                {
                    Thread.currentThread().interrupt();
                }
            }
        }.start();
        */
    long start = System.nanoTime();
    OutputStream out = socket.getOutputStream();
    out.write("POST / HTTP/1.1\r\n".getBytes());
    out.write("Host: localhost\r\n".getBytes());
    out.write("Content-Length: 16777216\r\n".getBytes());
    out.write("Content-Type: bytes\r\n".getBytes());
    out.write("Connection: close\r\n".getBytes());
    out.write("\r\n".getBytes());
    out.flush();
    byte[] requestContent = new byte[16777216];
    Arrays.fill(requestContent, (byte) 120);
    out.write(requestContent);
    out.flush();
    InputStream in = socket.getInputStream();
    String response = IO.toString(in);
    assertTrue(response.indexOf("200") > 0);
    // System.err.println(response);
    // long end = System.nanoTime();
    // System.out.println("upload time: " + TimeUnit.NANOSECONDS.toMillis(end - start));
    assertEquals(requestContent.length, total);
}
Also used : SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) SSLSocket(javax.net.ssl.SSLSocket) OutputStream(java.io.OutputStream) SSLContext(javax.net.ssl.SSLContext) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) KeyStore(java.security.KeyStore) FileInputStream(java.io.FileInputStream) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with FileInputStream

use of java.io.FileInputStream in project jetty.project by eclipse.

the class SSLSelectChannelConnectorLoadTest method startServer.

@BeforeClass
public static void startServer() throws Exception {
    String keystorePath = System.getProperty("basedir", ".") + "/src/test/resources/keystore";
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStorePath(keystorePath);
    sslContextFactory.setKeyStorePassword("storepwd");
    sslContextFactory.setKeyManagerPassword("keypwd");
    sslContextFactory.setTrustStorePath(keystorePath);
    sslContextFactory.setTrustStorePassword("storepwd");
    server = new Server();
    connector = new ServerConnector(server, sslContextFactory);
    server.addConnector(connector);
    server.setHandler(new EmptyHandler());
    server.start();
    KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
    try (InputStream stream = new FileInputStream(keystorePath)) {
        keystore.load(stream, "storepwd".toCharArray());
    }
    TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    trustManagerFactory.init(keystore);
    sslContext = SSLContext.getInstance("SSL");
    sslContext.init(null, trustManagerFactory.getTrustManagers(), null);
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) Server(org.eclipse.jetty.server.Server) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) KeyStore(java.security.KeyStore) FileInputStream(java.io.FileInputStream) BeforeClass(org.junit.BeforeClass)

Example 4 with FileInputStream

use of java.io.FileInputStream in project jetty.project by eclipse.

the class DatabaseLoginServiceTestServer method runscript.

public static int runscript(File scriptFile) throws Exception {
    //System.err.println("Running script:"+scriptFile.getAbsolutePath());
    try (FileInputStream fileStream = new FileInputStream(scriptFile)) {
        Loader.loadClass("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
        Connection connection = DriverManager.getConnection(__dbURL, "", "");
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        return ij.runScript(connection, fileStream, "UTF-8", out, "UTF-8");
    }
}
Also used : Connection(java.sql.Connection) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileInputStream(java.io.FileInputStream)

Example 5 with FileInputStream

use of java.io.FileInputStream in project buck by facebook.

the class DefaultAndroidDirectoryResolver method findNdkVersionFromDirectory.

/**
   * The method returns the NDK version of a path.
   * @param ndkDirectory Path to the folder that contains the NDK.
   * @return A string containing the NDK version or absent.
   */
public static Optional<String> findNdkVersionFromDirectory(Path ndkDirectory) {
    Path newNdk = ndkDirectory.resolve(NDK_POST_R11_VERSION_FILENAME);
    Path oldNdk = ndkDirectory.resolve(NDK_PRE_R11_VERSION_FILENAME);
    boolean newNdkPathFound = Files.exists(newNdk);
    boolean oldNdkPathFound = Files.exists(oldNdk);
    if (newNdkPathFound && oldNdkPathFound) {
        throw new HumanReadableException("Android NDK directory " + ndkDirectory + " can not " + "contain both properties files. Remove source.properties or RELEASE.TXT.");
    } else if (newNdkPathFound) {
        Properties sourceProperties = new Properties();
        try (FileInputStream fileStream = new FileInputStream(newNdk.toFile())) {
            sourceProperties.load(fileStream);
            return Optional.ofNullable(sourceProperties.getProperty("Pkg.Revision"));
        } catch (IOException e) {
            throw new HumanReadableException("Failed to read NDK version from " + newNdk + ".");
        }
    } else if (oldNdkPathFound) {
        try (BufferedReader reader = Files.newBufferedReader(oldNdk, Charsets.UTF_8)) {
            // around since we should consider them equivalent.
            return Optional.ofNullable(reader.readLine().split("\\s+")[0].replace("r10e-rc4", "r10e"));
        } catch (IOException e) {
            throw new HumanReadableException("Failed to read NDK version from " + oldNdk + ".");
        }
    } else {
        throw new HumanReadableException(ndkDirectory + " does not contain a valid properties " + "file for Android NDK.");
    }
}
Also used : Path(java.nio.file.Path) HumanReadableException(com.facebook.buck.util.HumanReadableException) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream)

Aggregations

FileInputStream (java.io.FileInputStream)14180 File (java.io.File)6801 IOException (java.io.IOException)6283 InputStream (java.io.InputStream)4121 FileOutputStream (java.io.FileOutputStream)2210 FileNotFoundException (java.io.FileNotFoundException)2002 InputStreamReader (java.io.InputStreamReader)1733 BufferedInputStream (java.io.BufferedInputStream)1593 Test (org.junit.Test)1548 BufferedReader (java.io.BufferedReader)1414 Properties (java.util.Properties)1410 ArrayList (java.util.ArrayList)960 OutputStream (java.io.OutputStream)753 ByteArrayInputStream (java.io.ByteArrayInputStream)599 HashMap (java.util.HashMap)597 ZipEntry (java.util.zip.ZipEntry)575 DataInputStream (java.io.DataInputStream)549 GZIPInputStream (java.util.zip.GZIPInputStream)435 KeyStore (java.security.KeyStore)430 ByteArrayOutputStream (java.io.ByteArrayOutputStream)407