You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by si...@apache.org on 2009/04/14 03:50:15 UTC
svn commit: r764661 -
/maven/components/trunk/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java
Author: sisbell
Date: Tue Apr 14 01:50:15 2009
New Revision: 764661
URL: http://svn.apache.org/viewvc?rev=764661&view=rev
Log:
Lazy loading of model input stream.
Modified:
maven/components/trunk/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java
Modified: maven/components/trunk/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java?rev=764661&r1=764660&r2=764661&view=diff
==============================================================================
--- maven/components/trunk/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java (original)
+++ maven/components/trunk/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java Tue Apr 14 01:50:15 2009
@@ -111,7 +111,6 @@
}
initializeProperties( model );
-
}
public PomClassicDomainModel(Model model) throws IOException {
@@ -122,23 +121,9 @@
this.model = model;
this.isMostSpecialized = b;
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- Writer out = null;
- MavenXpp3Writer writer = new MavenXpp3Writer();
- try
- {
- out = WriterFactory.newXmlWriter( baos );
- writer.write( out, model );
- }
- finally
- {
- if ( out != null )
- {
- out.close();
- }
- }
+
initializeProperties( model );
- inputBytes = baos.toByteArray();
+
}
public File getParentFile()
@@ -213,27 +198,62 @@
*
* @return XML model as string
*/
- public String asString()
+ public String asString() throws IOException
{
- try
- {
- return IOUtil.toString( ReaderFactory.newXmlReader( new ByteArrayInputStream( inputBytes ) ) );
- }
- catch ( IOException ioe )
- {
- // should not occur: everything is in-memory
- return "";
- }
+ if(inputBytes == null)
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ Writer out = null;
+ MavenXpp3Writer writer = new MavenXpp3Writer();
+ try
+ {
+ out = WriterFactory.newXmlWriter( baos );
+ writer.write( out, model );
+ }
+ finally
+ {
+ if ( out != null )
+ {
+ out.close();
+ }
+ }
+ inputBytes = baos.toByteArray();
+ }
+
+ return IOUtil.toString( ReaderFactory.newXmlReader( new ByteArrayInputStream( inputBytes ) ) );
}
/**
* @see org.apache.maven.shared.model.InputStreamDomainModel#getInputStream()
*/
- public InputStream getInputStream()
+ public InputStream getInputStream() throws IOException
{
- byte[] copy = new byte[inputBytes.length];
- System.arraycopy( inputBytes, 0, copy, 0, inputBytes.length );
- return new ByteArrayInputStream( copy );
+ if(inputBytes != null)
+ {
+ byte[] copy = new byte[inputBytes.length];
+ System.arraycopy( inputBytes, 0, copy, 0, inputBytes.length );
+ return new ByteArrayInputStream( copy );
+ }
+ else
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ Writer out = null;
+ MavenXpp3Writer writer = new MavenXpp3Writer();
+ try
+ {
+ out = WriterFactory.newXmlWriter( baos );
+ writer.write( out, model );
+ }
+ finally
+ {
+ if ( out != null )
+ {
+ out.close();
+ }
+ }
+ inputBytes = baos.toByteArray();
+ return new ByteArrayInputStream(inputBytes);
+ }
}
/**