当前位置: 首页>>代码示例>>Java>>正文


Java IOUtil.close方法代码示例

本文整理汇总了Java中org.codehaus.plexus.util.IOUtil.close方法的典型用法代码示例。如果您正苦于以下问题:Java IOUtil.close方法的具体用法?Java IOUtil.close怎么用?Java IOUtil.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.codehaus.plexus.util.IOUtil的用法示例。


在下文中一共展示了IOUtil.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getManifest

import org.codehaus.plexus.util.IOUtil; //导入方法依赖的package包/类
private Manifest getManifest(FileObject root) {
    FileObject manifestFo = root.getFileObject("META-INF/MANIFEST.MF");
    if (manifestFo != null) {
        InputStream is = null;
        try {
            is = manifestFo.getInputStream();
            return new Manifest(is);
        } catch (IOException ex) {
            //Exceptions.printStackTrace(ex);
        } finally {
            IOUtil.close(is);
        }
    }
    return null;

}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:MavenWhiteListQueryImpl.java

示例2: loadPublicPackagesPatterns

import org.codehaus.plexus.util.IOUtil; //导入方法依赖的package包/类
private static List<Pattern> loadPublicPackagesPatterns(Project project) {
    List<Pattern> toRet = new ArrayList<Pattern>();
    String[] params = PluginPropertyUtils.getPluginPropertyList(project, 
            MavenNbModuleImpl.GROUPID_MOJO, MavenNbModuleImpl.NBM_PLUGIN, //NOI18N
            "publicPackages", "publicPackage", "manifest"); //NOI18N
    if (params != null) {
        toRet = prepareMavenPublicPackagesPatterns(params);
    } else {
        FileObject obj = project.getProjectDirectory().getFileObject(MANIFEST_PATH);
        if (obj != null) {
            InputStream in = null;
            try {
                in = obj.getInputStream();
                Manifest man = new Manifest();
                man.read(in);
                String value = man.getMainAttributes().getValue(ATTR_PUBLIC_PACKAGE);
                toRet = prepareManifestPublicPackagesPatterns(value);
            } catch (Exception ex) {
                Exceptions.printStackTrace(ex);
            } finally {
                IOUtil.close(in);
            }
        }
    }
    return toRet;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:AccessQueryImpl.java

示例3: copyToCacheDir

import org.codehaus.plexus.util.IOUtil; //导入方法依赖的package包/类
private FileObject copyToCacheDir(InputStream in) throws IOException {
    FileObject cacheDir = cacheDir();
    FileObject file = cacheDir.getFileObject("checkstyle-checker.xml");
    if (file == null) {
        file = cacheDir.createData("checkstyle-checker", "xml");
    }
    InputStream inst = in;
    OutputStream outst = null;
    try {
        outst = file.getOutputStream();
        FileUtil.copy(in, outst);
    } finally {
        IOUtil.close(inst);
        IOUtil.close(outst);
    }
    return file;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:AuxPropsImpl.java

示例4: fromXml

import org.codehaus.plexus.util.IOUtil; //导入方法依赖的package包/类
/**
 * Reads the {@link WebappStructure} from the specified file.
 *
 * @param file the file containing the webapp structure
 * @return the webapp structure
 * @throws IOException if an error occurred while reading the structure
 */
public WebappStructure fromXml( File file )
    throws IOException
{
    Reader reader = null;

    try
    {
        reader = ReaderFactory.newXmlReader( file );
        return (WebappStructure) XSTREAM.fromXML( reader );
    }
    finally
    {
        IOUtil.close( reader );
    }
}
 
开发者ID:zhegexiaohuozi,项目名称:maven-seimicrawler-plugin,代码行数:23,代码来源:WebappStructureSerializer.java

示例5: toXml

import org.codehaus.plexus.util.IOUtil; //导入方法依赖的package包/类
/**
 * Saves the {@link WebappStructure} to the specified file.
 *
 * @param webappStructure the structure to save
 * @param targetFile the file to use to save the structure
 * @throws IOException if an error occurred while saving the webapp structure
 */
public void toXml( WebappStructure webappStructure, File targetFile )
    throws IOException
{
    // CHECKSTYLE_OFF: LineLength
    Writer writer = null;
    try
    {
        if ( !targetFile.getParentFile().exists() && !targetFile.getParentFile().mkdirs() )
        {
            throw new IOException( "Could not create parent [" + targetFile.getParentFile().getAbsolutePath() + "]" );
        }

        if ( !targetFile.exists() && !targetFile.createNewFile() )
        {
            throw new IOException( "Could not create file [" + targetFile.getAbsolutePath() + "]" );
        }
        writer = WriterFactory.newXmlWriter( targetFile );
        XSTREAM.toXML( webappStructure, writer );
    }
    finally
    {
        IOUtil.close( writer );
    }
    // CHECKSTYLE_ON: LineLength
}
 
开发者ID:zhegexiaohuozi,项目名称:maven-seimicrawler-plugin,代码行数:33,代码来源:WebappStructureSerializer.java

示例6: writeFile

import org.codehaus.plexus.util.IOUtil; //导入方法依赖的package包/类
private static void writeFile( File outputFile, Reader reader )
    throws DaemonGeneratorException
{
    FileWriter out = null;

    try
    {
        outputFile.getParentFile().mkdirs();
        out = new FileWriter( outputFile );

        IOUtil.copy( reader, out );
    }
    catch ( IOException e )
    {
        throw new DaemonGeneratorException( "Error writing output file: " + outputFile.getAbsolutePath(), e );
    }
    finally
    {
        IOUtil.close( reader );
        IOUtil.close( out );
    }
}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:23,代码来源:JavaServiceWrapperDaemonGenerator.java

示例7: getAppAssemblerBooterVersion

import org.codehaus.plexus.util.IOUtil; //导入方法依赖的package包/类
private static String getAppAssemblerBooterVersion()
    throws IOException, XmlPullParserException
{
    if ( appassemblerVersion == null )
    {
        MavenXpp3Reader reader = new MavenXpp3Reader();
        FileReader fileReader = new FileReader( getTestFile( "pom.xml" ) );
        try
        {
            appassemblerVersion = reader.read( fileReader ).getParent().getVersion();
        }
        finally
        {
            IOUtil.close( fileReader );
        }
    }
    return appassemblerVersion;
}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:19,代码来源:AbstractDaemonGeneratorTest.java

示例8: saveAndCompare

import org.codehaus.plexus.util.IOUtil; //导入方法依赖的package包/类
private void saveAndCompare( String expectedResource )
    throws IOException
{
    StringOutputStream string = new StringOutputStream();
    formattedProperties.save( string );

    StringOutputStream expected = new StringOutputStream();
    InputStream asStream = getClass().getResourceAsStream( expectedResource );
    try
    {
        IOUtil.copy( asStream, expected );
    }
    finally
    {
        IOUtil.close( asStream );
    }

    String unified = StringUtils.unifyLineSeparators( expected.toString() );
    assertEquals( unified, string.toString() );
}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:21,代码来源:FormattedPropertiesTest.java

示例9: execute

import org.codehaus.plexus.util.IOUtil; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void execute() throws MojoExecutionException {
    final Log log = getLog();

    File usedTargetFile = new File(targetFile.getAbsolutePath());
    log.info("creating source list file '" + usedTargetFile.getAbsolutePath() + "'");

    try {
        if (!usedTargetFile.getParentFile().exists() && !usedTargetFile.getParentFile().mkdirs())
            throw new MojoExecutionException("cannot create targetdir: " + usedTargetFile.getParentFile().getAbsolutePath());
        BufferedWriter writer = new BufferedWriter(new FileWriter(usedTargetFile));

        scanDirectories(project.getCompileSourceRoots(), writer);
        scanDirectories(project.getTestCompileSourceRoots(), writer);
        IOUtil.close(writer);
    } catch (IOException e) {
        throw new MojoExecutionException("IO-Error while generating source list file '" + usedTargetFile + "'", e);
    }
}
 
开发者ID:HostingAgency,项目名称:gwtcoverage-maven-plugin,代码行数:21,代码来源:SourcesListMojo.java

示例10: createArgFile

import org.codehaus.plexus.util.IOUtil; //导入方法依赖的package包/类
private void createArgFile( String filePath, List<String> lines )
    throws IOException
{
    final String EOL = System.getProperty( "line.separator", "\\n" );
    
    FileWriter writer = null;
    try
    {
        writer = new FileWriter( filePath );
        for ( String line : lines )
        {
            writer.append( line ).append( EOL );
        }

    }
    finally
    {
        IOUtil.close( writer );
    }
}
 
开发者ID:mojohaus,项目名称:exec-maven-plugin,代码行数:21,代码来源:ExecMojo.java

示例11: copyURLToFile

import org.codehaus.plexus.util.IOUtil; //导入方法依赖的package包/类
protected void copyURLToFile( URL url, File dest )
    throws IOException
{
    FileUtils.mkdir( dest.getParentFile().getAbsolutePath() );
    InputStream inputStream = url.openStream();
    try
    {
        OutputStream outputStream = new FileOutputStream( dest );
        try
        {
            IOUtil.copy( inputStream, outputStream );
        }
        finally
        {
            IOUtil.close( outputStream );
        }
    }
    finally
    {
        IOUtil.close( inputStream );
    }
}
 
开发者ID:mojohaus,项目名称:keytool,代码行数:23,代码来源:ResourceFixtures.java

示例12: getEncoding

import org.codehaus.plexus.util.IOUtil; //导入方法依赖的package包/类
protected String getEncoding( String requiredEncoding, File file, Log log )
    throws IOException
{
    FileInputStream fis = null;
    try
    {
        fis = new FileInputStream( file );
        CharsetDetector detector = new CharsetDetector();
        detector.setDeclaredEncoding( requiredEncoding );
        detector.setText( new BufferedInputStream( fis ) );
        CharsetMatch[] charsets = detector.detectAll();
        if ( charsets == null )
        {
            return null;
        }
        else
        {
            return charsets[0].getName();
        }
    }
    finally
    {
        IOUtil.close( fis );
    }
}
 
开发者ID:mojohaus,项目名称:extra-enforcer-rules,代码行数:26,代码来源:RequireEncoding.java

示例13: writeFile

import org.codehaus.plexus.util.IOUtil; //导入方法依赖的package包/类
protected void writeFile( String filePath, String content )
    throws IOException
{
    FileOutputStream fs = new FileOutputStream( filePath );
    try
    {
        IOUtil.copy( content, fs );
    }
    finally
    {
        if ( fs != null )
        {
            IOUtil.close( fs );
        }
    }
}
 
开发者ID:mojohaus,项目名称:maven-native,代码行数:17,代码来源:AbstractDependencyTest.java

示例14: writeStringToFile

import org.codehaus.plexus.util.IOUtil; //导入方法依赖的package包/类
/**
 * Writes the given <code>data</code> to the given <code>file</code> using the specified <code>encoding</code>.
 *
 * @param data is the {@link String} to write.
 * @param file is the {@link File} to write to.
 * @param encoding is the encoding to use for writing the file.
 * @throws MojoExecutionException if anything goes wrong.
 */
protected void writeStringToFile( String data, File file, String encoding )
    throws MojoExecutionException
{

    OutputStream outStream = null;
    Writer writer = null;
    try
    {
        outStream = new FileOutputStream( file );
        writer = new OutputStreamWriter( outStream, encoding );
        writer.write( data );
    }
    catch ( IOException e )
    {
        throw new MojoExecutionException( "Failed to write to " + file, e );
    }
    finally
    {
        // resource-handling not perfectly solved but we do not want to require java 1.7
        // and this is not a server application.
        IOUtil.close( writer );
        IOUtil.close( outStream );
    }
}
 
开发者ID:mojohaus,项目名称:flatten-maven-plugin,代码行数:33,代码来源:FlattenMojo.java

示例15: getVersion

import org.codehaus.plexus.util.IOUtil; //导入方法依赖的package包/类
@Override
public String getVersion( MavenProject mavenProject )
    throws ExternalVersionException
{
    String versionString = null;

    File versionFile = new File( mavenProject.getBasedir(), versionFilePath );
    BufferedReader reader = null;
    try
    {
        reader = new BufferedReader( new FileReader( versionFile ) );
        // just return the first line of the file, any other format is NOT supported.
        versionString = reader.readLine();
    }
    catch ( IOException e )
    {
        throw new ExternalVersionException( "Failed to read version file: [" + versionFile.getAbsolutePath() + "]",
                                            e );
    }
    finally
    {
        IOUtil.close( reader );
    }

    return versionString;
}
 
开发者ID:bdemers,项目名称:maven-external-version,代码行数:27,代码来源:FileStrategy.java


注:本文中的org.codehaus.plexus.util.IOUtil.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。