libextractor-java

GNU libextractor
Log | Files | Refs | README | LICENSE

commit 60a38f04f14a7c32816aea8017c88c9f0ca58743
parent 4b8f98396d9ce9d193ad3d38ad8820858b658788
Author: Christian Grothoff <christian@grothoff.org>
Date:   Fri,  1 Jan 2010 00:29:25 +0000

updating code to work with libextractor 0.6

Diffstat:
Aorg/gnu/libextractor/MetaData.java | 149+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 149 insertions(+), 0 deletions(-)

diff --git a/org/gnu/libextractor/MetaData.java b/org/gnu/libextractor/MetaData.java @@ -0,0 +1,148 @@ +/* + This file is part of libextractor. + (C) 2002, 2003, 2004, 2007, 2010 Vidyut Samanta and Christian Grothoff + + libextractor is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 2, or (at your + option) any later version. + + libextractor is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with libextractor; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + */ +package org.gnu.libextractor; + +import java.util.ArrayList; +import java.io.File; +import java.io.FileInputStream; + +/** + * An item of meta data extracted by GNU libextractor. + * + * @see Extractor + * @author Christian Grothoff + */ +public final class MetaData { + + /** + * Format is unknown. + */ + public static final int METAFORMAT_UNKNOWN = 0; + + /** + * 0-terminated, UTF-8 encoded string. "data_len" + * is strlen(data)+1. + */ + public static final int METAFORMAT_UTF8 = 1; + + /** + * Some kind of binary format, see given Mime type. + */ + public static final int METAFORMAT_BINARY = 2; + + /** + * 0-terminated string. The specific encoding is unknown. + * "data_len" is strlen(data)+1. + */ + public static final int METAFORMAT_C_STRING = 3; + + + /** + * Cached list of Strings describing keyword types. + */ + private final static String[] typeCache_; + + static { + typeCache_ = new String[Extractor.getMaxTypeInternal()]; + } + + /** + * LE type number for this meta data item. + */ + public final int type; + + /** + * LE format given for the meta data. + */ + public final int format; + + /** + * The meta data itself. + */ + public final byte[] meta; + + /** + * Mime-type of the meta data. + */ + public final String meta_mime; + + + /** + * Constructor is only called from "native" code. + * + * @param t type of the meta data + * @param f format of the meta data + * @param m the actual meta data + * @param mm mime type of the meta data + */ + private MetaData (int t, + int f, + byte[] m, + String mm) { + this.type = t; + this.format = f; + this.meta = m; + this.meta_mime = mm; + } + + + public String toString() { + return getTypeAsString() + " - " + getMetaDataAsString (); + } + + + /** + * Return the meta data as a "String" (if the format + * type permits this). + * + * @return null if the format of the meta data is unknown + */ + public String getMetaDataAsString () { + switch (format) { + case METAFORMAT_C_STRING: + return new String (meta); + case METAFORMAT_UTF8: + try { + return new String (meta, "UTF-8"); + } catch (java.io.UnsupportedEncodingException uee) { + // Java should ALWAYS support UTF-8 + throw new Error (uee); + } + case METAFORMAT_BINARY: + return "(binary, " + meta.length + " bytes)"; + default: + return null; + } + + } + + + /** + * @return description of this meta data item as a string + */ + public String getTypeAsString() { + if (typeCache_[type] == null) + typeCache_[type] + = Extractor.getTypeAsStringInternal(type); + return typeCache_[type]; + } + + +} // end of MetaData +\ No newline at end of file