本文整理汇总了Java中com.ibm.commons.util.io.StreamUtil.close方法的典型用法代码示例。如果您正苦于以下问题:Java StreamUtil.close方法的具体用法?Java StreamUtil.close怎么用?Java StreamUtil.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.ibm.commons.util.io.StreamUtil
的用法示例。
在下文中一共展示了StreamUtil.close方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
}
}
示例2: 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$
}
}
示例3: 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);
}
}
示例4: 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);
}
}
示例5: 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;
}
示例6: 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);
}
}
示例7: 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);
}
}
示例8: 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;
}
示例9: instantiateDb
import com.ibm.commons.util.io.StreamUtil; //导入方法依赖的package包/类
private static String instantiateDb(final String basename) throws IOException {
File dbFile = File.createTempFile(basename, ".nsf"); //$NON-NLS-1$
Platform.getInstance().log("{0} location is {1}", basename, dbFile.getAbsolutePath()); //$NON-NLS-1$
FileOutputStream fos = new FileOutputStream(dbFile);
InputStream is = AllTests.class.getResourceAsStream("/" + basename + ".nsf"); //$NON-NLS-1$ //$NON-NLS-2$
StreamUtil.copyStream(is, fos);
fos.flush();
StreamUtil.close(fos);
StreamUtil.close(is);
return dbFile.getAbsolutePath();
}
示例10: getAccessTokenForAuthorizedUser
import com.ibm.commons.util.io.StreamUtil; //导入方法依赖的package包/类
public void getAccessTokenForAuthorizedUser() throws Exception {
HttpPost method = null;
int responseCode = HttpStatus.SC_OK;
String responseBody = null;
InputStream content = null;
try {
HttpClient client = new DefaultHttpClient();
StringBuffer url = new StringBuffer(2048);
url.append(getAccessTokenURL()).append("?");
url.append(BASECAMP_OAUTH2_TYPE).append('=').append(getApplicationType());
url.append('&');
url.append(BASECAMP_OAUTH2_REDIRECTURI).append('=').append(URLEncoder.encode(getClient_uri(), "UTF-8"));
url.append('&');
url.append(Configuration.OAUTH2_CLIENT_ID).append('=').append(URLEncoder.encode(getConsumerKey(), "UTF-8"));
url.append('&');
url.append(Configuration.OAUTH2_CLIENT_SECRET).append('=').append(URLEncoder.encode(getConsumerSecret(), "UTF-8"));
url.append('&');
url.append(Configuration.OAUTH2_CODE).append('=').append(URLEncoder.encode(getAuthorization_code(), "UTF-8"));
method = new HttpPost(url.toString());
HttpResponse httpResponse =client.execute(method);
responseCode = httpResponse.getStatusLine().getStatusCode();
content = httpResponse.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(content));
try {
responseBody = StreamUtil.readString(reader);
} finally {
StreamUtil.close(reader);
}
} catch (Exception e) {
throw new OAuthException(e, "getAccessToken failed with Exception: <br>" + e);
} finally {
if(content != null) {
content.close();
}
}
if (responseCode != HttpStatus.SC_OK) {
getAccessTokenForAuthorizedUsingPOST();
return;
// if (responseCode == HttpStatus.SC_UNAUTHORIZED) {
// throw new Exception("getAccessToken failed with Response Code: Unauthorized (401),<br>Msg: " + responseBody);
// } else if (responseCode == HttpStatus.SC_BAD_REQUEST) {
// throw new Exception("getAccessToken failed with Response Code: Bad Request (400),<br>Msg: " + responseBody);
// } else if (responseCode == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
// throw new Exception("getAccessToken failed with Response Code: Internal Server error (500),<br>Msg: " + responseBody);
// } else {
// throw new Exception("getAccessToken failed with Response Code: (" + responseCode + "),<br>Msg: " + responseBody);
// }
} else {
setOAuthData(responseBody); //save the returned data
}
}