本文整理汇总了Java中org.codehaus.plexus.util.IOUtil类的典型用法代码示例。如果您正苦于以下问题:Java IOUtil类的具体用法?Java IOUtil怎么用?Java IOUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IOUtil类属于org.codehaus.plexus.util包,在下文中一共展示了IOUtil类的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;
}
示例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;
}
示例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;
}
示例4: 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);
}
}
示例5: 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 );
}
示例6: testConfigurationMerging
import org.codehaus.plexus.util.IOUtil; //导入依赖的package包/类
public void testConfigurationMerging()
throws Exception
{
XMLUnit.setNormalizeWhitespace( true );
InputStream resourceAsStream = getClass().getResourceAsStream( "/components-1.xml" );
transformer.processResource( "components-1.xml", resourceAsStream,
Collections.<Relocator> emptyList() );
resourceAsStream.close();
InputStream resourceAsStream1 = getClass().getResourceAsStream( "/components-2.xml" );
transformer.processResource( "components-1.xml", resourceAsStream1,
Collections.<Relocator> emptyList() );
resourceAsStream1.close();
final InputStream resourceAsStream2 = getClass().getResourceAsStream( "/components-expected.xml" );
Diff diff = XMLUnit.compareXML(
IOUtil.toString( resourceAsStream2, "UTF-8" ),
IOUtil.toString( transformer.getTransformedResource(), "UTF-8" ) );
//assertEquals( IOUtil.toString( getClass().getResourceAsStream( "/components-expected.xml" ), "UTF-8" ),
// IOUtil.toString( transformer.getTransformedResource(), "UTF-8" ).replaceAll("\r\n", "\n") );
resourceAsStream2.close();
XMLAssert.assertXMLIdentical( diff, true );
}
开发者ID:javiersigler,项目名称:apache-maven-shade-plugin,代码行数:24,代码来源:ComponentsXmlResourceTransformerTest.java
示例7: 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 );
}
}
示例8: 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
}
示例9: 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();
}
示例10: 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 );
}
}
示例11: 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;
}
示例12: 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() );
}
示例13: 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);
}
}
示例14: 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 );
}
}
示例15: 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 );
}
}