diff options
4 files changed, 22 insertions, 7 deletions
diff --git a/src/main/java/com/healthmarketscience/jackcess/Row.java b/src/main/java/com/healthmarketscience/jackcess/Row.java index e5d797d..08eaa62 100644 --- a/src/main/java/com/healthmarketscience/jackcess/Row.java +++ b/src/main/java/com/healthmarketscience/jackcess/Row.java @@ -19,11 +19,13 @@ USA package com.healthmarketscience.jackcess; +import java.io.IOException; import java.util.Date; import java.util.Map; import java.math.BigDecimal; import com.healthmarketscience.jackcess.complex.ComplexValueForeignKey; +import com.healthmarketscience.jackcess.util.OleBlob; /** @@ -102,7 +104,15 @@ public interface Row extends Map<String,Object> /** * Convenience method which gets the value for the row with the given name, - * casting it to a ComplexValueForeignKey (DataType COMPLEX_TYPE). + * casting it to a {@link ComplexValueForeignKey} (DataType COMPLEX_TYPE). */ public ComplexValueForeignKey getForeignKey(String name); + + /** + * Convenience method which gets the value for the row with the given name, + * converting it to an {@link OleBlob} (DataTypes OLE). + * </p> + * Note, <i>the OleBlob should be closed after use</i>. + */ + public OleBlob getBlob(String name) throws IOException; } diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/RowImpl.java b/src/main/java/com/healthmarketscience/jackcess/impl/RowImpl.java index 34071ad..dcd4d20 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/RowImpl.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/RowImpl.java @@ -19,12 +19,14 @@ USA package com.healthmarketscience.jackcess.impl; +import java.io.IOException; import java.util.LinkedHashMap; import java.util.Date; import java.math.BigDecimal; import com.healthmarketscience.jackcess.Row; import com.healthmarketscience.jackcess.complex.ComplexValueForeignKey; +import com.healthmarketscience.jackcess.util.OleBlob; /** @@ -103,6 +105,11 @@ public class RowImpl extends LinkedHashMap<String,Object> implements Row return (ComplexValueForeignKey)get(name); } + public OleBlob getBlob(String name) throws IOException { + byte[] bytes = getBytes(name); + return ((bytes != null) ? OleBlob.Builder.fromInternalData(bytes) : null); + } + @Override public String toString() { return CustomToStringStyle.valueBuilder("Row[" + _id + "]") diff --git a/src/main/java/com/healthmarketscience/jackcess/util/OleBlob.java b/src/main/java/com/healthmarketscience/jackcess/util/OleBlob.java index 18ae5b7..54f63af 100644 --- a/src/main/java/com/healthmarketscience/jackcess/util/OleBlob.java +++ b/src/main/java/com/healthmarketscience/jackcess/util/OleBlob.java @@ -31,7 +31,7 @@ import java.sql.Blob; import com.healthmarketscience.jackcess.impl.OleUtil; /** - * Extentions of the Blob interface with additional functionality for working + * Extensions of the Blob interface with additional functionality for working * with the OLE content from an access database. The ole data type in access * has a wide range of functionality (including wrappers with nested wrappers * with nested filesystems!), and jackcess only supports a small portion of @@ -56,10 +56,9 @@ import com.healthmarketscience.jackcess.impl.OleUtil; * <p/> * <b>Example for interpreting an existing OLE field:</b> * <pre> - * byte[] oleBytes = row.getBytes("MyOleColumn"); * OleBlob oleBlob = null; * try { - * oleBlob = OleBlob.Builder.fromInternalData(oleBlob); + * oleBlob = row.getBlob("MyOleColumn"); * Content content = oleBlob.getContent() * if(content.getType() == OleBlob.ContentType.SIMPLE_PACKAGE) { * FileOutputStream out = ...; diff --git a/src/test/java/com/healthmarketscience/jackcess/util/OleBlobTest.java b/src/test/java/com/healthmarketscience/jackcess/util/OleBlobTest.java index 3a1cc05..250d433 100644 --- a/src/test/java/com/healthmarketscience/jackcess/util/OleBlobTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/util/OleBlobTest.java @@ -101,8 +101,7 @@ public class OleBlobTest extends TestCase for(Row row : t) { try { - blob = OleBlob.Builder.fromInternalData( - row.getBytes("ole")); + blob = row.getBlob("ole"); OleBlob.Content content = blob.getContent(); assertSame(blob, content.getBlob()); assertSame(content, blob.getContent()); @@ -171,7 +170,7 @@ public class OleBlobTest extends TestCase try { String name = row.getString("name"); - oleBlob = OleBlob.Builder.fromInternalData(row.getBytes("ole_data")); + oleBlob = row.getBlob("ole_data"); OleBlob.Content content = oleBlob.getContent(); Attachment attach = null; if(content.getType() != OleBlob.ContentType.LINK) { |