本文整理匯總了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 );
}
}