Mercurial Hosting > luan
comparison src/luan/modules/Utils.java @ 1367:836e00bf7ce2
add Lucene backup_to
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 18 Jun 2019 16:27:03 -0600 |
parents | 1a68fc55a80c |
children | eb8b35dccd99 |
comparison
equal
deleted
inserted
replaced
1366:ae2321a09723 | 1367:836e00bf7ce2 |
---|---|
91 { | 91 { |
92 ByteArrayOutputStream out = new ByteArrayOutputStream(); | 92 ByteArrayOutputStream out = new ByteArrayOutputStream(); |
93 copyAll(in,out); | 93 copyAll(in,out); |
94 return out.toByteArray(); | 94 return out.toByteArray(); |
95 } | 95 } |
96 /* | |
97 public static boolean exists(File file) { | |
98 try { | |
99 return file.exists() && file.getName().equals(file.getCanonicalFile().getName()); | |
100 } catch(IOException e) { | |
101 throw new RuntimeException(e); | |
102 } | |
103 } | |
104 */ | |
105 /* | |
106 private static File toFile(String path) { | |
107 if( path.contains("//") ) | |
108 return null; | |
109 File file = new File(path); | |
110 return file.exists() ? file : null; | |
111 } | |
112 | 96 |
113 private static URL toUrl(String path) { | |
114 if( path.indexOf(':') == -1 ) | |
115 return null; | |
116 if( path.startsWith("classpath:") ) { | |
117 path = path.substring(10); | |
118 if( path.contains("//") ) | |
119 return null; | |
120 URL url; | |
121 if( !path.contains("#") ) { | |
122 url = ClassLoader.getSystemResource(path); | |
123 } else { | |
124 String[] a = path.split("#"); | |
125 url = ClassLoader.getSystemResource(a[0]); | |
126 if( url==null ) { | |
127 for( int i=1; i<a.length; i++ ) { | |
128 url = ClassLoader.getSystemResource(a[0]+"/"+a[i]); | |
129 if( url != null ) { | |
130 try { | |
131 url = new URL(url,"."); | |
132 } catch(MalformedURLException e) { | |
133 throw new RuntimeException(e); | |
134 } | |
135 break; | |
136 } | |
137 } | |
138 } | |
139 } | |
140 return url==null ? null : url; | |
141 } | |
142 try { | |
143 return new URL(path); | |
144 } catch(MalformedURLException e) {} | |
145 return null; | |
146 } | |
147 | |
148 static boolean exists(String path) { | |
149 return toFile(path)!=null || toUrl(path)!=null; | |
150 } | |
151 */ | |
152 | |
153 | |
154 | |
155 /* replace by uri"os:..." | |
156 | |
157 // process | |
158 | |
159 public static class ProcessException extends IOException { | |
160 private ProcessException(String msg) { | |
161 super(msg); | |
162 } | |
163 } | |
164 | |
165 public static void checkProcess(Process proc) | |
166 throws IOException | |
167 { | |
168 try { | |
169 proc.waitFor(); | |
170 } catch(InterruptedException e) { | |
171 throw new RuntimeException(e); | |
172 } | |
173 int exitVal = proc.exitValue(); | |
174 if( exitVal != 0 ) { | |
175 Reader err = new InputStreamReader(proc.getErrorStream()); | |
176 String error = readAll(err); | |
177 err.close(); | |
178 throw new ProcessException(error); | |
179 } | |
180 } | |
181 | |
182 public static String getOutput(Process proc) | |
183 throws IOException | |
184 { | |
185 Reader in = new InputStreamReader(proc.getInputStream()); | |
186 String s = readAll(in); | |
187 in.close(); | |
188 return s; | |
189 } | |
190 | |
191 public static String execProcess(String... cmd) | |
192 throws IOException | |
193 { | |
194 Process proc = Runtime.getRuntime().exec(cmd); | |
195 String s = getOutput(proc); | |
196 checkProcess(proc); | |
197 return s; | |
198 } | |
199 */ | |
200 } | 97 } |