source: main/trunk/greenstone2/common-src/src/jdbmedit/JdbKeys.java@ 21403

Last change on this file since 21403 was 21403, checked in by davidb, 14 years ago

Code was working for Ascii characters, but not for Unicode values > 128. More careful prescription of utf-8 used in code

File size: 2.3 KB
Line 
1/**********************************************************************
2 *
3 * JdbKeys.java --
4 * A component of the Greenstone digital library software
5 * from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * Copyright (C) 2009 The New Zealand Digital Library Project
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 **********************************************************************/
25
26import java.io.IOException;
27import java.io.UnsupportedEncodingException;
28import java.io.OutputStreamWriter;
29import java.io.PrintWriter;
30import java.util.Properties;
31import java.util.ArrayList;
32
33import jdbm.RecordManager;
34import jdbm.RecordManagerFactory;
35import jdbm.helper.FastIterator;
36import jdbm.htree.HTree;
37
38public class JdbKeys
39{
40 static private PrintWriter utf8out = null;
41
42 static
43 {
44 try {
45 OutputStreamWriter osw = new OutputStreamWriter(System.out, "UTF-8");
46 utf8out = new PrintWriter(osw, true);
47 }
48 catch (UnsupportedEncodingException e) {
49 System.out.println(e);
50 }
51 }
52
53 public static void print_usage()
54 {
55 System.err.println("Usage: java JdbKeys database-name");
56 System.exit(-1);
57 }
58
59
60 public static void main(String[] args)
61 {
62 if (args.length != 1) {
63 print_usage();
64 }
65
66 String dbname = args[0];
67
68 try {
69 JdbmAPI jdbm_api = new JdbmAPI(dbname,true);
70
71 ArrayList keys = jdbm_api.get_keys();
72
73 int keys_len = keys.size();
74 for (int i=0; i<keys_len; i++) {
75 String key = (String) keys.get(i);
76 utf8out.println(key);
77 }
78
79 jdbm_api.close();
80 }
81 catch (IOException e) {
82 e.printStackTrace();
83 }
84 }
85
86}
Note: See TracBrowser for help on using the repository browser.