diff options
author | James Ahlborn <jtahlborn@yahoo.com> | 2013-08-02 03:26:24 +0000 |
---|---|---|
committer | James Ahlborn <jtahlborn@yahoo.com> | 2013-08-02 03:26:24 +0000 |
commit | c622f4dc2fea16a2f4b45e5c83c8e5df66a3a797 (patch) | |
tree | 9ab5688ff3991076ef866b61e28ace8ac4683cf3 | |
parent | 764aa75ad6c2ba78ccd5e84bd7c5ee8f39e9c9d7 (diff) | |
download | jackcess-c622f4dc2fea16a2f4b45e5c83c8e5df66a3a797.tar.gz jackcess-c622f4dc2fea16a2f4b45e5c83c8e5df66a3a797.zip |
use ExportUtil to implement display method
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@767 f203690c-595d-4dc9-a70b-905162fa7fd2
-rw-r--r-- | src/java/com/healthmarketscience/jackcess/impl/TableImpl.java | 38 |
1 files changed, 6 insertions, 32 deletions
diff --git a/src/java/com/healthmarketscience/jackcess/impl/TableImpl.java b/src/java/com/healthmarketscience/jackcess/impl/TableImpl.java index a42b7c2..125508e 100644 --- a/src/java/com/healthmarketscience/jackcess/impl/TableImpl.java +++ b/src/java/com/healthmarketscience/jackcess/impl/TableImpl.java @@ -27,7 +27,9 @@ King of Prussia, PA 19406 package com.healthmarketscience.jackcess.impl; +import java.io.BufferedWriter; import java.io.IOException; +import java.io.StringWriter; import java.nio.ByteBuffer; import java.nio.charset.Charset; import java.util.ArrayList; @@ -53,6 +55,7 @@ import com.healthmarketscience.jackcess.Row; import com.healthmarketscience.jackcess.RowId; import com.healthmarketscience.jackcess.Table; import com.healthmarketscience.jackcess.util.ErrorHandler; +import com.healthmarketscience.jackcess.util.ExportUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -2119,38 +2122,9 @@ public class TableImpl implements Table */ public String display(long limit) throws IOException { reset(); - StringBuilder rtn = new StringBuilder(); - for(Iterator<ColumnImpl> iter = _columns.iterator(); iter.hasNext(); ) { - ColumnImpl col = iter.next(); - rtn.append(col.getName()); - if (iter.hasNext()) { - rtn.append("\t"); - } - } - rtn.append("\n"); - Row row; - int rowCount = 0; - while ((rowCount++ < limit) && (row = getNextRow()) != null) { - for(Iterator<Object> iter = row.values().iterator(); iter.hasNext(); ) { - Object obj = iter.next(); - if (obj instanceof byte[]) { - byte[] b = (byte[]) obj; - rtn.append(ByteUtil.toHexString(b)); - //This block can be used to easily dump a binary column to a file - /*java.io.File f = java.io.File.createTempFile("ole", ".bin"); - java.io.FileOutputStream out = new java.io.FileOutputStream(f); - out.write(b); - out.flush(); - out.close();*/ - } else { - rtn.append(String.valueOf(obj)); - } - if (iter.hasNext()) { - rtn.append("\t"); - } - } - rtn.append("\n"); - } + StringWriter rtn = new StringWriter(); + new ExportUtil.Builder(getDefaultCursor()).setDelimiter("\t").setHeader(true) + .exportWriter(new BufferedWriter(rtn)); return rtn.toString(); } |