source: MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/Helpers.java @ 627

Last change on this file since 627 was 627, checked in by vronk, 14 years ago

introducing the user: only real change in GenericProxyAction?
the rest is just removed unused imports.

File size: 1.7 KB
Line 
1package eu.clarin.cmdi.mdservice.action;
2
3import java.io.IOException;
4import java.io.InputStream;
5import java.io.OutputStream;
6import java.io.PrintStream;
7
8import javax.xml.parsers.DocumentBuilder;
9import javax.xml.parsers.DocumentBuilderFactory;
10import javax.xml.parsers.FactoryConfigurationError;
11import javax.xml.parsers.ParserConfigurationException;
12
13import org.w3c.dom.Document;
14import org.xml.sax.SAXException;
15
16public class Helpers {
17
18        private static PrintStream log;
19       
20        public static Document readFSLS(String infile)
21        {
22                Document document = null;
23                try {
24                    DocumentBuilderFactory factory = 
25                    DocumentBuilderFactory.newInstance();
26                    DocumentBuilder builder = factory.newDocumentBuilder();
27                    document = builder.parse(infile);               
28                }
29                catch (FactoryConfigurationError e) {
30                    // unable to get a document builder factory
31                        notifyUser(e.getClass() + ": " + e.getLocalizedMessage());
32                } 
33                catch (ParserConfigurationException e) {
34                    // parser was unable to be configured
35                        notifyUser(e.getClass() + ": " + e.getLocalizedMessage());                     
36                }
37                catch (IOException e) {
38                    // i/o error
39                        notifyUser(e.getClass() + ": io-error " + e.getLocalizedMessage());                     
40                } catch (SAXException e) {
41                        // TODO Auto-generated catch block
42                        e.printStackTrace();
43                }
44               
45                return document;
46        }
47       
48        public static void notifyUser (String msg) {
49                if (log== null) { log = System.err; }
50                log.println(msg);
51               
52        }
53
54        public static void copy (InputStream in, OutputStream out) throws IOException, InterruptedException {           
55               
56                byte[] buffer = new byte[1024];
57                int len = in.read(buffer);
58                while (len != -1) {
59                    out.write(buffer, 0, len);
60                    len = in.read(buffer);
61                    if (Thread.interrupted()) {
62                        throw new InterruptedException();
63                    }
64                }
65        }
66
67}
Note: See TracBrowser for help on using the repository browser.