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


Java IOUtil.copy方法代码示例

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


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

示例1: extractJar

import org.codehaus.plexus.util.IOUtil; //导入方法依赖的package包/类
void extractJar(File jar, ManifestTransformer manifestTransformer) throws MojoExecutionException {
    try (JarFile jarFile = new JarFile(jar)) {
        for (Enumeration<JarEntry> jarEntries = jarFile.entries(); jarEntries.hasMoreElements(); ) {
            JarEntry jarEntry = jarEntries.nextElement();
            if (manifestTransformer.canTransform(jarEntry)) {
                jarEntry = manifestTransformer.transform(jarEntry);
            }
            if (!jarEntry.isDirectory() && !content.contains(jarEntry.getName())) {
                content.add(jarEntry.getName());
                makeDirsRecursively(jarEntry.getName());
                try (InputStream in = getInputStream(jarEntry, jarFile, manifestTransformer)) {
                    jarOutputStream.putNextEntry(jarEntry);
                    IOUtil.copy(in, jarOutputStream);
                }
            }
        }
    } catch (IOException e) {
        throw new MojoExecutionException("Error adding " + jar.getName() + " to target JAR: " + e.getMessage(), e);
    }
}
 
开发者ID:fstab,项目名称:promagent,代码行数:21,代码来源:AgentJar.java

示例2: addJavaSource

import org.codehaus.plexus.util.IOUtil; //导入方法依赖的package包/类
private void addJavaSource( Set<String> resources, JarOutputStream jos, String name, InputStream is,
                            List<Relocator> relocators, boolean consistentDates )
    throws IOException
{
    JarEntry jarEntry = new ConsistentJarEntry( name, consistentDates );
    jos.putNextEntry( jarEntry );

    String sourceContent = IOUtil.toString( new InputStreamReader( is, "UTF-8" ) );

    for ( Relocator relocator : relocators )
    {
        sourceContent = relocator.applyToSourceContent( sourceContent );
    }

    final Writer writer = new OutputStreamWriter( jos, "UTF-8" );
    IOUtil.copy( sourceContent, writer );
    writer.flush();

    resources.add( name );
}
 
开发者ID:javiersigler,项目名称:apache-maven-shade-plugin,代码行数:21,代码来源:DefaultShader.java

示例3: interpolateBaseDirAndRepo

import org.codehaus.plexus.util.IOUtil; //导入方法依赖的package包/类
private String interpolateBaseDirAndRepo( String content )
{
    StringReader sr = new StringReader( content );
    StringWriter result = new StringWriter();

    Map context = new HashMap();

    context.put( "BASEDIR", StringUtils.quoteAndEscape( getBasedir(), '"' ) );
    context.put( "REPO", StringUtils.quoteAndEscape( getRepo(), '"' ) );
    InterpolationFilterReader interpolationFilterReader = new InterpolationFilterReader( sr, context, "@", "@" );
    try
    {
        IOUtil.copy( interpolationFilterReader, result );
    }
    catch ( IOException e )
    {
        // shouldn't happen...
    }
    return result.toString();
}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:21,代码来源:Platform.java

示例4: 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

示例5: 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

示例6: merge

import org.codehaus.plexus.util.IOUtil; //导入方法依赖的package包/类
/**
 * Merges a list of source files. Create missing parent directories if
 * needed.
 *
 * @param mergedFile output file resulting from the merged step
 * @throws IOException when the merge step fails
 */
protected void merge(File mergedFile) throws IOException {
    mergedFile.getParentFile().mkdirs();

    try (InputStream sequence = new SequenceInputStream(new SourceFilesEnumeration(log, files, verbose, charset));
            OutputStream out = new FileOutputStream(mergedFile);
            InputStreamReader sequenceReader = new InputStreamReader(sequence, charset);
            OutputStreamWriter outWriter = new OutputStreamWriter(out, charset)) {
        log.info("Creating the merged file [" + ((verbose) ? mergedFile.getPath() : mergedFile.getName()) + "].");

        IOUtil.copy(sequenceReader, outWriter, bufferSize);
    } catch (IOException e) {
        log.error("Failed to concatenate files.", e);
        throw e;
    }
}
 
开发者ID:a1martin,项目名称:minifier-maven-plugin,代码行数:23,代码来源:ProcessFilesTask.java

示例7: logCompressionGains

import org.codehaus.plexus.util.IOUtil; //导入方法依赖的package包/类
/**
 * Logs compression gains.
 *
 * @param mergedFile input file resulting from the merged step
 * @param minifiedFile output file resulting from the minify step
 */
void logCompressionGains(File mergedFile, File minifiedFile) {
    try {
        File temp = File.createTempFile(minifiedFile.getName(), ".gz");

        try (InputStream in = new FileInputStream(minifiedFile);
                OutputStream out = new FileOutputStream(temp);
                GZIPOutputStream outGZIP = new GZIPOutputStream(out)) {
            IOUtil.copy(in, outGZIP, bufferSize);
        }

        log.info("Uncompressed size: " + mergedFile.length() + " bytes.");
        log.info("Compressed size: " + minifiedFile.length() + " bytes minified (" + temp.length()
                + " bytes gzipped).");

        temp.deleteOnExit();
    } catch (IOException e) {
        log.debug("Failed to calculate the gzipped file size.", e);
    }
}
 
开发者ID:a1martin,项目名称:minifier-maven-plugin,代码行数:26,代码来源:ProcessFilesTask.java

示例8: interpolateBaseDirAndRepo

import org.codehaus.plexus.util.IOUtil; //导入方法依赖的package包/类
private String interpolateBaseDirAndRepo( String content )
{
    StringReader sr = new StringReader( content );
    StringWriter result = new StringWriter();

    Map<Object, Object> context = new HashMap<Object, Object>();

    context.put( "BASEDIR", StringUtils.quoteAndEscape( getBasedir(), '"' ) );
    context.put( "REPO", StringUtils.quoteAndEscape( getRepo(), '"' ) );
    InterpolationFilterReader interpolationFilterReader = new InterpolationFilterReader( sr, context, "@", "@" );
    try
    {
        IOUtil.copy( interpolationFilterReader, result );
    }
    catch ( IOException e )
    {
        // shouldn't happen...
    }
    return result.toString();
}
 
开发者ID:mojohaus,项目名称:appassembler,代码行数:21,代码来源:Platform.java

示例9: 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

示例10: addJavaSource

import org.codehaus.plexus.util.IOUtil; //导入方法依赖的package包/类
private void addJavaSource(Set<String> resources, JarOutputStream jos, String name, InputStream is,
    List<Relocator> relocators)
    throws IOException {
  jos.putNextEntry(new JarEntry(name));

  String sourceContent = IOUtil.toString(new InputStreamReader(is, "UTF-8"));

  for (Relocator relocator : relocators) {
    sourceContent = relocator.applyToSourceContent(sourceContent);
  }

  OutputStreamWriter writer = new OutputStreamWriter(jos, "UTF-8");
  IOUtil.copy(sourceContent, writer);
  writer.flush();
  resources.add(name);
}
 
开发者ID:immutables,项目名称:maven-shade-plugin,代码行数:17,代码来源:DefaultShader.java

示例11: download

import org.codehaus.plexus.util.IOUtil; //导入方法依赖的package包/类
public static void download(LicenseInfo licenseInfo, File outputDir) throws IOException {
    File path = new File(outputDir, "raw/" + licenseInfo.getKey() + ".txt");
    path.getParentFile().mkdirs();
    URL url = new URL(licenseInfo.getUrl());

    InputStream in = null;
    OutputStream out = null;
    try {
        in = new BufferedInputStream(url.openConnection().getInputStream());
        out = new BufferedOutputStream(new FileOutputStream(path));

        IOUtil.copy(in, out);
    } finally {
        if (in != null) in.close();
        if (out != null) out.close();
    }
}
 
开发者ID:willowtreeapps,项目名称:saguaro,代码行数:18,代码来源:LicenseUtil.java

示例12: copy

import org.codehaus.plexus.util.IOUtil; //导入方法依赖的package包/类
public void copy() throws IOException
{
    for (Dependency mod : mods)
    {
        FileUtils.copyFileToDirectory(MavenHelper.getFile(mod), modsFolder);
    }
    for (Dependency config : configs)
    {
        File configFile = MavenHelper.getFile(config);
        if (config.getType().equals("zip"))
        {
            ZipFile zipFile = new ZipFile(configFile);
            Enumeration<? extends ZipEntry> enumeration = zipFile.entries();
            while (enumeration.hasMoreElements())
            {
                ZipEntry zipEntry = enumeration.nextElement();
                LOGGER.debug(zipEntry.getName());
                if (zipEntry.isDirectory())
                    //noinspection ResultOfMethodCallIgnored
                    new File(packData.getInstanceFolder(side), zipEntry.getName()).mkdir();
                else IOUtil.copy(zipFile.getInputStream(zipEntry), new FileWriter(new File(packData.getInstanceFolder(side), zipEntry.getName())));
            }
        }
        else FileUtils.copyFileToDirectory(configFile, packData.getInstanceFolder(side));
    }
}
 
开发者ID:DoubleDoorDevelopment,项目名称:D3Launcher,代码行数:27,代码来源:PackBuilder.java

示例13: writeFile

import org.codehaus.plexus.util.IOUtil; //导入方法依赖的package包/类
private void writeFile( String path, File destSh )
    throws IOException
{
    InputStream instream = null;
    OutputStream output = null;
    try
    {
        instream = getClass().getClassLoader().getResourceAsStream( path );
        if ( instream == null )
        {
            throw new FileNotFoundException( path );
        }
        destSh.createNewFile();
        output = new BufferedOutputStream( new FileOutputStream( destSh ) );
        IOUtil.copy( instream, output );
    }
    finally
    {
        IOUtil.close( instream );
        IOUtil.close( output );
    }
}
 
开发者ID:bitstrings,项目名称:nbm-maven,代码行数:23,代码来源:CreateClusterAppMojo.java

示例14: addFile

import org.codehaus.plexus.util.IOUtil; //导入方法依赖的package包/类
void addFile(File srcFile, String targetFileName, Directory targetDir) throws MojoExecutionException {
    String destPath = targetDir.getName() + targetFileName;
    if (content.contains(destPath)) {
        return;
    }
    makeDirsRecursively(destPath);
    content.add(destPath);
    try (InputStream in = new FileInputStream(srcFile)) {
        jarOutputStream.putNextEntry(new JarEntry(destPath));
        IOUtil.copy(in, jarOutputStream);
    } catch (IOException e) {
        throw new MojoExecutionException("Error adding " + srcFile.getName() + " to target JAR: " + e.getMessage(), e);
    }
}
 
开发者ID:fstab,项目名称:promagent,代码行数:15,代码来源:AgentJar.java

示例15: modifyOutputStream

import org.codehaus.plexus.util.IOUtil; //导入方法依赖的package包/类
public void modifyOutputStream( JarOutputStream jos, boolean consistentDates )
    throws IOException
{
    byte[] data = getTransformedResource();

    JarEntry entry = new ConsistentJarEntry( COMPONENTS_XML_PATH, consistentDates );
    jos.putNextEntry( entry );

    IOUtil.copy( data, jos );

    components.clear();
}
 
开发者ID:javiersigler,项目名称:apache-maven-shade-plugin,代码行数:13,代码来源:ComponentsXmlResourceTransformer.java


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