本文整理了Java中net.roboconf.core.utils.Utils.closeQuietly()
方法的一些代码示例,展示了Utils.closeQuietly()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.closeQuietly()
方法的具体详情如下:
包路径:net.roboconf.core.utils.Utils
类名称:Utils
方法名:closeQuietly
[英]Closes a stream quietly.
[中]静静地关闭一条小溪。
代码示例来源:origin: roboconf/roboconf-platform
/**
* Writes Java properties into a file.
* @param properties non-null properties
* @param file a properties file
* @throws IOException if writing failed
*/
public static void writePropertiesFile( Properties properties, File file ) throws IOException {
OutputStream out = null;
try {
out = new FileOutputStream( file );
properties.store( out, "" );
} finally {
closeQuietly( out );
}
}
代码示例来源:origin: roboconf/roboconf-platform
/**
* Reads properties from a file.
* @param file a properties file
* @return a {@link Properties} instance
* @throws IOException if reading failed
*/
public static Properties readPropertiesFile( File file ) throws IOException {
Properties result = new Properties();
InputStream in = null;
try {
in = new FileInputStream( file );
result.load( in );
} finally {
closeQuietly( in );
}
return result;
}
代码示例来源:origin: net.roboconf/roboconf-iaas-azure
private KeyStore getKeyStore(String keyStoreName, String password) throws IOException {
KeyStore ks = null;
FileInputStream fis = null;
try {
ks = KeyStore.getInstance("JKS");
char[] passwordArray = password.toCharArray();
fis = new java.io.FileInputStream(keyStoreName);
ks.load(fis, passwordArray);
} catch (Exception e) {
this.logger.severe( e.getMessage() );
}
finally {
if (fis != null) {
Utils.closeQuietly( fis );
}
}
return ks;
}
代码示例来源:origin: roboconf/roboconf-platform
@Override
public void run() {
final String prefix = this.errorLevel ? "-- ERROR --" : "";
BufferedReader br = null;
try {
InputStream is = this.errorLevel ? this.process.getErrorStream() : this.process.getInputStream();
br = new BufferedReader( new InputStreamReader( is, StandardCharsets.UTF_8 ));
for( String line = br.readLine(); line != null; line = br.readLine())
this.sb.append( prefix + line + "\n" );
} catch( IOException e ) {
this.logger.severe( Utils.writeExceptionButDoNotUseItForLogging( e ));
} finally {
Utils.closeQuietly( br );
}
}
}
代码示例来源:origin: roboconf/roboconf-platform
/**
* Appends a string into a file.
*
* @param s the string to write (not null)
* @param outputFile the file to write into
* @throws IOException if something went wrong
*/
public static void appendStringInto( String s, File outputFile ) throws IOException {
OutputStreamWriter fw = null;
try {
fw = new OutputStreamWriter( new FileOutputStream( outputFile, true ), StandardCharsets.UTF_8 );
fw.append( s );
} finally {
Utils.closeQuietly( fw );
}
}
代码示例来源:origin: net.roboconf/roboconf-doc-generator
private void writeCssFile() throws IOException {
InputStream in = null;
String location = this.options.get( DocConstants.OPTION_HTML_CSS_FILE );
try {
if( ! Utils.isEmptyOrWhitespaces( location ))
in = new FileInputStream( new File( location ));
else
in = getClass().getResourceAsStream( "/style.css" );
File cssFile = new File( this.outputDirectory, "style.css" );
Utils.copyStream( in, cssFile );
} finally {
Utils.closeQuietly( in );
}
}
}
代码示例来源:origin: roboconf/roboconf-platform
/**
* Finds a property in the MANIFEST file.
* @param propertyName the property's name
* @return the property's value, or null if it was not found
*/
public static String findManifestProperty( String propertyName ) {
String result = null;
InputStream is = null;
try {
is = ManifestUtils.class.getResourceAsStream( "/META-INF/MANIFEST.MF" );
Properties props = new Properties();
props.load( is );
result = findManifestProperty( props, propertyName );
} catch( IOException e ) {
Logger logger = Logger.getLogger( ManifestUtils.class.getName());
logger.warning( "Could not read the bundle manifest. " + e.getMessage());
} finally {
Utils.closeQuietly( is );
}
return result;
}
代码示例来源:origin: roboconf/roboconf-platform
private void writeCssFile() throws IOException {
InputStream in = null;
String location = this.options.get( DocConstants.OPTION_HTML_CSS_FILE );
try {
if( ! Utils.isEmptyOrWhitespaces( location ))
in = new FileInputStream( new File( location ));
else
in = getClass().getResourceAsStream( "/style.css" );
File cssFile = new File( this.outputDirectory, "style.css" );
Utils.copyStream( in, cssFile );
} finally {
Utils.closeQuietly( in );
}
}
}
代码示例来源:origin: roboconf/roboconf-platform
/**
* Parses a dockerfile to a list of commands.
* @throws IOException
* @param dockerfile a file
* @return a list of Docker commands
*/
public static List<DockerCommand> dockerfileToCommandList( File dockerfile ) throws IOException {
List<DockerCommand> result = new ArrayList<>();
FileInputStream in = new FileInputStream( dockerfile );
Logger logger = Logger.getLogger( DockerfileParser.class.getName());
BufferedReader br = null;
try {
br = new BufferedReader( new InputStreamReader( in, StandardCharsets.UTF_8 ));
String line;
while((line = br.readLine()) != null) {
DockerCommand cmd = DockerCommand.guess(line);
if( cmd != null )
result.add( cmd );
else
logger.fine("Ignoring unsupported Docker instruction: " + line );
}
} finally {
Utils.closeQuietly( br );
Utils.closeQuietly( in );
}
return result;
}
代码示例来源:origin: net.roboconf/roboconf-agent
/**
* Retrieve the agent's configuration from an URL.
* @param logger a logger
* @return the agent's data, or null if they could not be parsed
*/
public AgentProperties findParametersFromUrl( String url, Logger logger ) {
logger.info( "User data are being retrieved from URL: " + url );
AgentProperties result = null;
try {
URI uri = UriUtils.urlToUri( url );
Properties props = new Properties();
InputStream in = null;
try {
in = uri.toURL().openStream();
props.load( in );
} finally {
Utils.closeQuietly( in );
}
result = AgentProperties.readIaasProperties( props );
} catch( Exception e ) {
logger.fine( "Agent parameters could not be read from " + url );
result = null;
}
return result;
}
代码示例来源:origin: roboconf/roboconf-platform
/**
* Reads the content of an URL (assumed to be text content).
* @param url an URL
* @return a non-null string
* @throws IOException
* @throws URISyntaxException
*/
public static String readUrlContent( String url )
throws IOException, URISyntaxException {
InputStream in = null;
try {
URI uri = UriUtils.urlToUri( url );
in = uri.toURL().openStream();
ByteArrayOutputStream os = new ByteArrayOutputStream();
Utils.copyStreamSafely( in, os );
return os.toString( "UTF-8" );
} finally {
closeQuietly( in );
}
}
代码示例来源:origin: roboconf/roboconf-platform
@Test
public void testCloseQuietly() throws Exception {
InputStream in = null;
Utils.closeQuietly( in );
in = new ByteArrayInputStream( new byte[ 0 ]);
Utils.closeQuietly( in );
OutputStream out = new ByteArrayOutputStream();
Utils.closeQuietly( out );
out = null;
Utils.closeQuietly( out );
Reader reader = null;
Utils.closeQuietly( reader );
reader = new CharArrayReader( new char[ 0 ]);
Utils.closeQuietly( reader );
Writer writer = null;
Utils.closeQuietly( writer );
writer = new StringWriter();
Utils.closeQuietly( writer );
}
代码示例来源:origin: net.roboconf/roboconf-dm
@Override
public void execute() throws CommandException {
OutputStreamWriter fw = null;
try {
File f = new File( this.instr.getFilePath());
boolean append = f.exists() && f.length() > 0;
fw = new OutputStreamWriter( new FileOutputStream( f, true ), StandardCharsets.UTF_8 );
if( append )
fw.append( "\n" );
fw.append( this.instr.getContent());
} catch( IOException e ) {
throw new CommandException( e );
} finally {
Utils.closeQuietly( fw );
}
}
}
代码示例来源:origin: roboconf/roboconf-platform
Utils.closeQuietly( in );
代码示例来源:origin: net.roboconf/roboconf-iaas-azure
private String processGetRequest(URL url, String keyStore, String keyStorePassword)
throws UnrecoverableKeyException, KeyManagementException, KeyStoreException, NoSuchAlgorithmException, IOException {
SSLSocketFactory sslFactory = this.getSSLSocketFactory(keyStore, keyStorePassword);
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
con.setSSLSocketFactory(sslFactory);
con.setRequestMethod("GET");
con.addRequestProperty("x-ms-version", "2014-04-01");
InputStream responseStream = (InputStream) con.getContent();
try {
return getStringFromInputStream(responseStream);
} finally {
Utils.closeQuietly( responseStream );
}
}
代码示例来源:origin: roboconf/roboconf-platform
@Test
public void testCloseQuietly_silentInput() throws Exception {
InputStream in = new InputStream() {
@Override
public int read() throws IOException {
return 0;
}
@Override
public void close() throws IOException {
throw new IOException();
}
};
Utils.closeQuietly( in );
}
代码示例来源:origin: roboconf/roboconf-platform
@Test
public void testCloseQuietly_silentOutput() throws Exception {
OutputStream out = new OutputStream() {
@Override
public void write( int b ) throws IOException {
// nothing
}
@Override
public void close() throws IOException {
throw new IOException();
}
};
Utils.closeQuietly( out );
}
代码示例来源:origin: roboconf/roboconf-platform
@Test
public void testCloseQuietly_silentReader() throws Exception {
Reader reader = new Reader() {
@Override
public int read( char[] cbuf, int off, int len ) throws IOException {
return 0;
}
@Override
public void close() throws IOException {
throw new IOException();
}
};
Utils.closeQuietly( reader );
}
代码示例来源:origin: roboconf/roboconf-platform
@Test
public void testCloseQuietly_silentWriter() throws Exception {
Writer writer = new Writer() {
@Override
public void write( char[] arg0, int arg1, int arg2 ) throws IOException {
// nothing
}
@Override
public void flush() throws IOException {
// nothing
}
@Override
public void close() throws IOException {
throw new IOException();
}
};
Utils.closeQuietly( writer );
}
代码示例来源:origin: roboconf/roboconf-platform
/**
* Creates a ZIP file from the map.
* @param entryToContent a map (key = ZIP entry, value = entry content, null for a directory)
* @param targetZipFile
*/
public static void createZipFile( Map<String,String> entryToContent, File targetZipFile ) throws IOException {
ZipOutputStream zos = null;
try {
zos = new ZipOutputStream( new FileOutputStream( targetZipFile ));
for( Map.Entry<String,String> entry : entryToContent.entrySet()) {
zos.putNextEntry( new ZipEntry( entry.getKey()));
if( entry.getValue() != null ) {
ByteArrayInputStream is = new ByteArrayInputStream( entry.getValue().getBytes( "UTF-8" ));
try {
Utils.copyStreamUnsafelyUseWithCaution( is, zos );
} finally {
Utils.closeQuietly( is );
}
}
zos.closeEntry();
}
} finally {
Utils.closeQuietly( zos );
}
}
内容来源于网络,如有侵权,请联系作者删除!