[21395] | 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 | *
|
---|
[21402] | 8 | * Copyright (C) 2009 The New Zealand Digital Library Project
|
---|
[21395] | 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 |
|
---|
[21402] | 26 | import java.io.IOException;
|
---|
[21403] | 27 | import java.io.UnsupportedEncodingException;
|
---|
| 28 | import java.io.OutputStreamWriter;
|
---|
| 29 | import java.io.PrintWriter;
|
---|
[21402] | 30 | import java.util.Properties;
|
---|
| 31 | import java.util.ArrayList;
|
---|
| 32 |
|
---|
[21395] | 33 | import jdbm.RecordManager;
|
---|
| 34 | import jdbm.RecordManagerFactory;
|
---|
| 35 | import jdbm.helper.FastIterator;
|
---|
| 36 | import jdbm.htree.HTree;
|
---|
| 37 |
|
---|
| 38 | public class JdbKeys
|
---|
| 39 | {
|
---|
[21403] | 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 |
|
---|
[21395] | 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 {
|
---|
[21402] | 69 | JdbmAPI jdbm_api = new JdbmAPI(dbname,true);
|
---|
[21403] | 70 |
|
---|
[21402] | 71 | ArrayList keys = jdbm_api.get_keys();
|
---|
[21403] | 72 |
|
---|
[21402] | 73 | int keys_len = keys.size();
|
---|
| 74 | for (int i=0; i<keys_len; i++) {
|
---|
| 75 | String key = (String) keys.get(i);
|
---|
[21403] | 76 | utf8out.println(key);
|
---|
[21402] | 77 | }
|
---|
| 78 |
|
---|
| 79 | jdbm_api.close();
|
---|
[21395] | 80 | }
|
---|
| 81 | catch (IOException e) {
|
---|
| 82 | e.printStackTrace();
|
---|
| 83 | }
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | } |
---|