Search in sources :

Example 36 with FileInputStream

use of java.io.FileInputStream in project tomcat by apache.

the class ExtensionValidator method addSystemResource.

/**
     * Checks to see if the given system JAR file contains a MANIFEST, and adds
     * it to the container's manifest resources.
     *
     * @param jarFile The system JAR whose manifest to add
     * @throws IOException Error reading JAR file
     */
public static void addSystemResource(File jarFile) throws IOException {
    try (InputStream is = new FileInputStream(jarFile)) {
        Manifest manifest = getManifest(is);
        if (manifest != null) {
            ManifestResource mre = new ManifestResource(jarFile.getAbsolutePath(), manifest, ManifestResource.SYSTEM);
            containerManifestResources.add(mre);
        }
    }
}
Also used : FileInputStream(java.io.FileInputStream) JarInputStream(java.util.jar.JarInputStream) InputStream(java.io.InputStream) Manifest(java.util.jar.Manifest) FileInputStream(java.io.FileInputStream)

Example 37 with FileInputStream

use of java.io.FileInputStream in project tomcat by apache.

the class ConfigFileLoader method getInputStream.

/**
     * Load the resource from the specified location.
     *
     * @param location The location for the resource of interest. The location
     *                 may be a URL or a file path. Relative paths will be
     *                 resolved against CATALINA_BASE.
     *
     * @return The InputStream for the given resource. The caller is responsible
     *         for closing this stream when it is no longer used.
     *
     * @throws IOException If an InputStream cannot be created using the
     *                     provided location
     */
public static InputStream getInputStream(String location) throws IOException {
    // Location was originally always a file before URI support was added so
    // try file first.
    File f = new File(location);
    if (!f.isAbsolute()) {
        f = new File(CATALINA_BASE_FILE, location);
    }
    if (f.isFile()) {
        return new FileInputStream(f);
    }
    // File didn't work so try URI.
    // Using resolve() enables the code to handle relative paths that did
    // not point to a file
    URI uri;
    if (CATALINA_BASE_URI != null) {
        uri = CATALINA_BASE_URI.resolve(location);
    } else {
        uri = URI.create(location);
    }
    // Obtain the input stream we need
    try {
        URL url = uri.toURL();
        return url.openConnection().getInputStream();
    } catch (IllegalArgumentException e) {
        throw new IOException(sm.getString("configFileLoader.cannotObtainURL", location), e);
    }
}
Also used : IOException(java.io.IOException) File(java.io.File) URI(java.net.URI) FileInputStream(java.io.FileInputStream) URL(java.net.URL)

Example 38 with FileInputStream

use of java.io.FileInputStream in project zeppelin by apache.

the class NotebookAuthorization method loadFromFile.

private static void loadFromFile() throws IOException {
    File settingFile = new File(filePath);
    LOG.info(settingFile.getAbsolutePath());
    if (!settingFile.exists()) {
        // nothing to read
        return;
    }
    FileInputStream fis = new FileInputStream(settingFile);
    InputStreamReader isr = new InputStreamReader(fis);
    BufferedReader bufferedReader = new BufferedReader(isr);
    StringBuilder sb = new StringBuilder();
    String line;
    while ((line = bufferedReader.readLine()) != null) {
        sb.append(line);
    }
    isr.close();
    fis.close();
    String json = sb.toString();
    NotebookAuthorizationInfoSaving info = gson.fromJson(json, NotebookAuthorizationInfoSaving.class);
    authInfo = info.authInfo;
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 39 with FileInputStream

use of java.io.FileInputStream in project zookeeper by apache.

the class SnapshotFormatter method run.

public void run(String snapshotFileName) throws IOException {
    InputStream is = new CheckedInputStream(new BufferedInputStream(new FileInputStream(snapshotFileName)), new Adler32());
    InputArchive ia = BinaryInputArchive.getArchive(is);
    FileSnap fileSnap = new FileSnap(null);
    DataTree dataTree = new DataTree();
    Map<Long, Integer> sessions = new HashMap<Long, Integer>();
    fileSnap.deserialize(dataTree, sessions, ia);
    printDetails(dataTree, sessions);
}
Also used : FileSnap(org.apache.zookeeper.server.persistence.FileSnap) BufferedInputStream(java.io.BufferedInputStream) HashMap(java.util.HashMap) CheckedInputStream(java.util.zip.CheckedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) InputArchive(org.apache.jute.InputArchive) BinaryInputArchive(org.apache.jute.BinaryInputArchive) CheckedInputStream(java.util.zip.CheckedInputStream) FileInputStream(java.io.FileInputStream) Adler32(java.util.zip.Adler32)

Example 40 with FileInputStream

use of java.io.FileInputStream in project zookeeper by apache.

the class LoadFromLogTest method testPad.

/**
     * Simulates ZOOKEEPER-1069 and verifies that flush() before padLogFile
     * fixes it.
     */
@Test
public void testPad() throws Exception {
    File tmpDir = ClientBase.createTmpDir();
    FileTxnLog txnLog = new FileTxnLog(tmpDir);
    TxnHeader txnHeader = new TxnHeader(0xabcd, 0x123, 0x123, Time.currentElapsedTime(), OpCode.create);
    Record txn = new CreateTxn("/Test", new byte[0], null, false, 1);
    txnLog.append(txnHeader, txn);
    FileInputStream in = new FileInputStream(tmpDir.getPath() + "/log." + Long.toHexString(txnHeader.getZxid()));
    BinaryInputArchive ia = BinaryInputArchive.getArchive(in);
    FileHeader header = new FileHeader();
    header.deserialize(ia, "fileheader");
    LOG.info("Received magic : " + header.getMagic() + " Expected : " + FileTxnLog.TXNLOG_MAGIC);
    Assert.assertTrue("Missing magic number ", header.getMagic() == FileTxnLog.TXNLOG_MAGIC);
}
Also used : BinaryInputArchive(org.apache.jute.BinaryInputArchive) CreateTxn(org.apache.zookeeper.txn.CreateTxn) FileTxnLog(org.apache.zookeeper.server.persistence.FileTxnLog) Record(org.apache.jute.Record) File(java.io.File) FileHeader(org.apache.zookeeper.server.persistence.FileHeader) FileInputStream(java.io.FileInputStream) TxnHeader(org.apache.zookeeper.txn.TxnHeader) Test(org.junit.Test)

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