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);
}
}
}
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);
}
}
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;
}
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);
}
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);
}
Aggregations