Last change
on this file since 5944 was 5944, checked in by cs025, 20 years ago |
Index document type, metadata extensions
|
-
Property svn:keywords
set to
Author Date Id Revision
|
File size:
1.2 KB
|
Line | |
---|
1 | package org.greenstone.gsdl3.gs3build.doctypes;
|
---|
2 |
|
---|
3 | import java.io.*;
|
---|
4 | import java.net.URL;
|
---|
5 |
|
---|
6 | public class DocumentLoader
|
---|
7 | {
|
---|
8 | public static String getAsString(InputStream in)
|
---|
9 | { StringBuffer reply;
|
---|
10 | byte data[] = new byte[1024];
|
---|
11 | int databytes;
|
---|
12 |
|
---|
13 | reply = new StringBuffer();
|
---|
14 |
|
---|
15 | try
|
---|
16 | {
|
---|
17 | do
|
---|
18 | { databytes = in.read(data);
|
---|
19 | if (databytes > 0)
|
---|
20 | { reply.append(new String(data, 0, databytes));
|
---|
21 | }
|
---|
22 | } while (databytes >= 0);
|
---|
23 | }
|
---|
24 | catch (IOException io)
|
---|
25 | {
|
---|
26 | }
|
---|
27 |
|
---|
28 | return reply.toString();
|
---|
29 | }
|
---|
30 |
|
---|
31 | public static String getAsString(File file)
|
---|
32 | { FileInputStream in;
|
---|
33 | String reply = null;
|
---|
34 |
|
---|
35 | try
|
---|
36 | { in = new FileInputStream(file);
|
---|
37 | if (in == null)
|
---|
38 | { return null;
|
---|
39 | }
|
---|
40 | reply = getAsString(in);
|
---|
41 |
|
---|
42 | in.close();
|
---|
43 | }
|
---|
44 | catch (IOException io)
|
---|
45 | { return null;
|
---|
46 | }
|
---|
47 | return reply;
|
---|
48 | }
|
---|
49 |
|
---|
50 | public static String getAsString(URL url)
|
---|
51 | { if (url.toString().startsWith("file://"))
|
---|
52 | { File file = new File(url.toString().substring(7));
|
---|
53 | return getAsString(file);
|
---|
54 | }
|
---|
55 | else if (url.toString().startsWith("file:/"))
|
---|
56 | { File file = new File(url.toString().substring(5));
|
---|
57 | return getAsString(file);
|
---|
58 | }
|
---|
59 |
|
---|
60 | return null;
|
---|
61 | }
|
---|
62 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.