From: James Ahlborn Date: Fri, 2 Aug 2013 03:26:24 +0000 (+0000) Subject: use ExportUtil to implement display method X-Git-Tag: jackcess-2.0.0~14 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c622f4dc2fea16a2f4b45e5c83c8e5df66a3a797;p=jackcess.git 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 --- 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 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 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(); }