[jboss-svn-commits] JBL Code SVN: r24360 - in labs/jbossrules/trunk/drools-repository/src: test/java/org/drools/repository and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Dec 11 22:42:34 EST 2008
Author: michael.neale at jboss.com
Date: 2008-12-11 22:42:33 -0500 (Thu, 11 Dec 2008)
New Revision: 24360
Modified:
labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/repository/AssetItem.java
labs/jbossrules/trunk/drools-repository/src/test/java/org/drools/repository/AssetItemTest.java
Log:
GUVNOR-78
Modified: labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/repository/AssetItem.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/repository/AssetItem.java 2008-12-11 21:31:29 UTC (rev 24359)
+++ labs/jbossrules/trunk/drools-repository/src/main/java/org/drools/repository/AssetItem.java 2008-12-12 03:42:33 UTC (rev 24360)
@@ -2,6 +2,7 @@
import java.io.ByteArrayInputStream;
import java.io.InputStream;
+import java.io.ByteArrayOutputStream;
import java.util.Calendar;
import java.util.Iterator;
@@ -144,6 +145,10 @@
Property data = ruleNode.getProperty( CONTENT_PROPERTY_BINARY_NAME );
return data.getStream();
} else {
+ if ( ruleNode.hasProperty(CONTENT_PROPERTY_NAME)) {
+ Property data = ruleNode.getProperty( CONTENT_PROPERTY_NAME );
+ return data.getStream();
+ }
return null;
}
} catch ( Exception e ) {
@@ -164,32 +169,32 @@
public byte[] getBinaryContentAsBytes() {
try {
Node ruleNode = getVersionContentNode();
- if ( ruleNode.hasProperty( CONTENT_PROPERTY_BINARY_NAME ) ) {
- Property data = ruleNode.getProperty( CONTENT_PROPERTY_BINARY_NAME );
- InputStream in = data.getStream();
+ if (isBinary()) {
+ Property data = ruleNode.getProperty( CONTENT_PROPERTY_BINARY_NAME );
+ InputStream in = data.getStream();
- // Create the byte array to hold the data
- byte[] bytes = new byte[(int) data.getLength()];
+ // Create the byte array to hold the data
+ byte[] bytes = new byte[(int) data.getLength()];
- // Read in the bytes
- int offset = 0;
- int numRead = 0;
- while ( offset < bytes.length && (numRead = in.read( bytes,
- offset,
- bytes.length - offset )) >= 0 ) {
- offset += numRead;
- }
+ // Read in the bytes
+ int offset = 0;
+ int numRead = 0;
+ while ( offset < bytes.length && (numRead = in.read( bytes,
+ offset,
+ bytes.length - offset )) >= 0 ) {
+ offset += numRead;
+ }
- // Ensure all the bytes have been read in
- if ( offset < bytes.length ) {
- throw new RulesRepositoryException( "Could not completely read asset " + getName() );
- }
+ // Ensure all the bytes have been read in
+ if ( offset < bytes.length ) {
+ throw new RulesRepositoryException( "Could not completely read asset " + getName() );
+ }
- // Close the input stream and return bytes
- in.close();
- return bytes;
+ // Close the input stream and return bytes
+ in.close();
+ return bytes;
} else {
- return null;
+ return getContent().getBytes();
}
} catch ( Exception e ) {
log.error( e );
Modified: labs/jbossrules/trunk/drools-repository/src/test/java/org/drools/repository/AssetItemTest.java
===================================================================
--- labs/jbossrules/trunk/drools-repository/src/test/java/org/drools/repository/AssetItemTest.java 2008-12-11 21:31:29 UTC (rev 24359)
+++ labs/jbossrules/trunk/drools-repository/src/test/java/org/drools/repository/AssetItemTest.java 2008-12-12 03:42:33 UTC (rev 24360)
@@ -161,12 +161,17 @@
AssetItem ruleItem1 = getRepo().loadDefaultPackage().addAsset("testGetContent", "test content");
ruleItem1.updateContent( "test content" );
+ ruleItem1.updateFormat("drl");
assertNotNull(ruleItem1);
assertNotNull(ruleItem1.getNode());
assertEquals("test content", ruleItem1.getContent());
assertFalse(ruleItem1.isBinary());
+
+ assertNotNull(ruleItem1.getBinaryContentAsBytes());
+ assertNotNull(ruleItem1.getBinaryContentAttachment());
+ String content = new String(ruleItem1.getBinaryContentAsBytes());
}
More information about the jboss-svn-commits
mailing list