File: MetaData.java

package info (click to toggle)
libextractor-java 1.0.0-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,616 kB
  • sloc: sh: 10,270; ansic: 749; java: 168; makefile: 33
file content (148 lines) | stat: -rw-r--r-- 3,596 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
     This file is part of libextractor.
     (C) 2002, 2003, 2004, 2007, 2010, 2012 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 3, 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