本文整理汇总了Java中com.ibm.commons.util.io.StreamUtil类的典型用法代码示例。如果您正苦于以下问题:Java StreamUtil类的具体用法?Java StreamUtil怎么用?Java StreamUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StreamUtil类属于com.ibm.commons.util.io包,在下文中一共展示了StreamUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadLibrary
import com.ibm.commons.util.io.StreamUtil; //导入依赖的package包/类
public String loadLibrary(String libName) throws InterpretException {
String result = null;
if (_libs.containsKey(libName)) {
InputStream is = null;
try {
is = getClass().getClassLoader().getResourceAsStream(_libs.get(libName));
result = StreamUtil.readString(is);
} catch (IOException ex) {
throw new InterpretException(ex);
} finally {
try {
is.close();
} catch (Exception e) {
}
}
}
return result;
}
示例2: createFeatureJar
import com.ibm.commons.util.io.StreamUtil; //导入依赖的package包/类
protected void createFeatureJar(final IProject project) throws Exception {
JarOutputStream jar = null;
InputStream is = null;
try {
String directory = _outputDir + "/features/"; // $NON-NLS-1$
Utils.createDirectory(directory);
// Create the Jar
jar = new JarOutputStream(new FileOutputStream(directory + _projectDef.name + ".feature_" + _projectDef.version + ".jar")); // $NON-NLS-1$ $NON-NLS-2$
JarEntry entry = new JarEntry("feature.xml"); // $NON-NLS-1$
jar.putNextEntry(entry);
String contents = getResourceFile(FEATURE_RES);
is = new ByteArrayInputStream(contents.getBytes("UTF-8")); // $NON-NLS-1$
Utils.writeJarEntry(jar, is);
} catch (Exception e) {
throw new Exception("Error creating Feature JAR", e); // $NLX-JdbcPluginGenerator.ErrorcreatingFeatureJar-1$
} finally {
StreamUtil.close(is);
if (jar != null) {
jar.close();
}
}
}
示例3: copyFilesIntoProject
import com.ibm.commons.util.io.StreamUtil; //导入依赖的package包/类
public static void copyFilesIntoProject(final IProject project, final String folder, final List<String> fileList) throws Exception {
try {
for (String file : fileList) {
FileInputStream fis = new FileInputStream(file);
try {
String libFile = new File(file).getName();
IFile libFileProj = project.getFile(folder + "/" + libFile);
libFileProj.create(fis, true, null);
} finally {
StreamUtil.close(fis);
}
}
} catch (Exception e) {
throw new Exception("Could not copy JARs into project", e); // $NLX-ProjectUtils.Couldnotcopyjarsintoproject-1$
}
}
示例4: copyResource
import com.ibm.commons.util.io.StreamUtil; //导入依赖的package包/类
public void copyResource(String dir, String resourceName) throws IOException {
String res = "com/ibm/xsp/eclipse/tools/resources/"+resourceName;
InputStream is = getClass().getClassLoader().getResourceAsStream(res);
if(is!=null) {
try {
File d = new File(baseDirectory,dir);
d.mkdirs();
int pos = resourceName.lastIndexOf('/');
if(pos>=0) {
resourceName = resourceName.substring(pos+1);
}
OutputStream os = new FileOutputStream(new File(d,resourceName));
try {
StreamUtil.copyStream(is,os);
} finally {
os.close();
}
}
finally {
is.close();
}
}
}
示例5: copyResource
import com.ibm.commons.util.io.StreamUtil; //导入依赖的package包/类
private void copyResource(ZipInputStream zin, ZipEntry ze) throws IOException {
String resourcePath = ze.getName();
String targetFileName = StringUtil.replace(resourcePath, '/', File.separatorChar);
File targetFile = new File(installDirectory,targetFileName);
File targetDir = targetFile.getParentFile();
targetDir.mkdirs();
// Add it to the file list
writer.write(resourcePath);
writer.newLine();
OutputStream os = new FileOutputStream(targetFile);
try {
StreamUtil.copyStream(zin, os);
} finally {
os.close();
}
}
示例6: flush
import com.ibm.commons.util.io.StreamUtil; //导入依赖的package包/类
@Override
public void flush() throws IOException {
if (!streamOpened) {
this.createEncoderOutputStream();
streamOpened = true;
}
this.finish();
if (!preventCache) {
httpServletResponse.setContentLength((int)byteStreamCache.getLength());
// And copy the entire content
InputStream is = byteStreamCache.getInputStream();
OutputStream out = httpServletResponse.getOutputStream();
StreamUtil.copyStream(is, out);
out.flush();
byteStreamCache.clear();
}
outputStream.flush();
}
示例7: getUsingDocument
import com.ibm.commons.util.io.StreamUtil; //导入依赖的package包/类
@Override
public UsingDocument getUsingDocument(final boolean create) {
Document doc = database_.getDocumentByID(USING_NOTE);
if (doc != null) {
return new UsingDocument(doc);
} else if (create) {
try {
InputStream is = AboutDocument.class.getResourceAsStream("/org/openntf/domino/design/impl/dxl_helpusingdocument.xml");
String dxl = StreamUtil.readString(is);
is.close();
DxlImporter importer = getAncestorSession().createDxlImporter();
importer.setDesignImportOption(DxlImporter.DesignImportOption.REPLACE_ELSE_CREATE);
importer.setReplicaRequiredForReplaceOrUpdate(false);
importer.importDxl(dxl, database_);
doc = database_.getDocumentByID(USING_NOTE);
return new UsingDocument(doc);
} catch (IOException e) {
DominoUtils.handleException(e);
}
}
return null;
}
示例8: createSiteXml
import com.ibm.commons.util.io.StreamUtil; //导入依赖的package包/类
protected void createSiteXml() throws Exception {
FileOutputStream fos = null;
try {
Utils.createDirectory(_outputDir);
String contents = getResourceFile(SITE_RES);
File f = new File(_outputDir, "site.xml"); // $NON-NLS-1$
fos = new FileOutputStream(f);
fos.write(contents.getBytes("UTF-8")); // $NON-NLS-1$
} catch (Exception e) {
throw new Exception("Error creating \"site.xml\"", e); // $NLX-JdbcPluginGenerator.Errorcreatingsitexml-1$
} finally {
StreamUtil.close(fos);
}
}
示例9: writeFile
import com.ibm.commons.util.io.StreamUtil; //导入依赖的package包/类
public static void writeFile(final String name, final IContainer container, final String content) throws Exception {
InputStream is = null;
try {
IFile file = container.getFile(new Path(name));
is = new ByteArrayInputStream(content.getBytes(file.getCharset()));
file.create(is, true, null);
} catch (Exception e) {
String msg = StringUtil.format("Could not create the file \"{0}\"", name); // $NLX-ProjectUtils.Couldnotcreatethefile0-1$
throw new Exception(msg, e);
} finally {
StreamUtil.close(is);
}
}
示例10: getFileContents
import com.ibm.commons.util.io.StreamUtil; //导入依赖的package包/类
public static String getFileContents(final Bundle bundle, final String resName) throws Exception {
URL resURL = bundle.getResource(resName);
String content;
InputStream is = resURL.openStream();
try {
java.util.Scanner s = new java.util.Scanner(is, "UTF-8").useDelimiter("\\A"); // $NON-NLS-1$ $NON-NLS-2$
content = s.hasNext() ? s.next() : "";
} finally {
StreamUtil.close(is);
}
return content;
}
示例11: writeJarEntry
import com.ibm.commons.util.io.StreamUtil; //导入依赖的package包/类
public static void writeJarEntry(final JarOutputStream jar, final InputStream is) throws Exception {
BufferedInputStream bis = new BufferedInputStream(is);
try {
byte[] buf = new byte[8192];
while (true) {
int count = bis.read(buf);
if (count == -1)
break;
jar.write(buf, 0, count);
}
jar.closeEntry();
} finally {
StreamUtil.close(bis);
}
}
示例12: flushStream
import com.ibm.commons.util.io.StreamUtil; //导入依赖的package包/类
public void flushStream() throws ServiceException {
if(streamFlushed) {
return;
}
streamFlushed = true;
if(os!=null) {
try {
os.flush();
if(bs!=null) {
// Emit the GZIP header if necessary
if(os instanceof GZIPOutputStream) {
((GZIPOutputStream)os).finish();
httpResponse.setHeader(HEADER_CONTENT_ENCODING, ENCODING_GZIP);
}
// We have the length from the buffer
httpResponse.setContentLength((int)bs.getLength());
// And copy the entire content
InputStream is = bs.getInputStream();
OutputStream out = getHttpResponse().getOutputStream();
StreamUtil.copyStream(is, out);
out.flush();
} else {
// Finish the GZIP stream
if(os instanceof GZIPOutputStream) {
((GZIPOutputStream)os).finish();
httpResponse.setHeader(HEADER_CONTENT_ENCODING, ENCODING_GZIP);
}
}
} catch(IOException ex) {
throw new ServiceException(ex,"Error when sending data to the client"); // $NLX-HttpServiceEngine.Errorwhensendingdatatotheclient-1$
}
}
}
示例13: loadResourceFactory
import com.ibm.commons.util.io.StreamUtil; //导入依赖的package包/类
public IJdbcResourceFactory loadResourceFactory(String name) throws ResourceFactoriesException {
InputStream is = getFileContent(name);
try {
return loadJDBCConnection(is, name);
} finally {
StreamUtil.close(is);
}
}
示例14: readConfig
import com.ibm.commons.util.io.StreamUtil; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
public static Map<String, String> readConfig(String[][] extraConfig) {
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
// ResourceBundle bundle = ResourceBundle.getBundle("com.ibm.xsp.test.framework.config");
HashMap<String, String> config = new HashMap<String, String>();
try {
URL url = contextClassLoader.getResource("com/ibm/xsp/test/framework/config.properties");
if (url != null) {
String pathToConfig = url.getPath();
if (StringUtil.isNotEmpty(pathToConfig)) {
if (pathToConfig.contains("com.ibm.xsp.test.framework"))
throw new RuntimeException("The first detected config.properties file is in the ...test.framework plugin (at "
+ url.getPath()
+ "). Please instead add a config.properties file in your library test project, "
+ "and rearrange the test project .classpath file to search in the test project first, "
+ "before the plugin dependancies.");
}
}
InputStream in = url.openStream();
try{
Properties props = new Properties();
props.load(in);
config.putAll((Map)props);
}finally{
StreamUtil.close(in);
}
} catch (IOException e1) {
e1.printStackTrace();
throw new RuntimeException(e1.toString(), e1);
}
if( null != extraConfig && extraConfig.length > 0){
for (String[] keyToValue : extraConfig) {
config.put(keyToValue[0], keyToValue[1]);
}
}
return config;
}
示例15: processToStream
import com.ibm.commons.util.io.StreamUtil; //导入依赖的package包/类
public void processToStream(RestServiceEngine engine, FileHelper fh) {// byte[]
// byteFile)
// {
try {
InputStream is = getFileSteam(fh);
OutputStream os = engine.getHttpResponse().getOutputStream();
// os.write(byteFile);
StreamUtil.copyStream(is, os);
os.close();
is.close();
} catch (Exception e) {
e.printStackTrace();
}
}