Mercurial Hosting > luan
comparison core/src/luan/modules/IoLuan.java @ 747:d3a1e9a48a94
add unzip
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 14 Jul 2016 20:03:01 -0600 |
parents | 293c397e8dee |
children | de2418d11786 |
comparison
equal
deleted
inserted
replaced
746:293c397e8dee | 747:d3a1e9a48a94 |
---|---|
29 import java.net.NetworkInterface; | 29 import java.net.NetworkInterface; |
30 import java.net.MalformedURLException; | 30 import java.net.MalformedURLException; |
31 import java.net.UnknownHostException; | 31 import java.net.UnknownHostException; |
32 import java.util.Enumeration; | 32 import java.util.Enumeration; |
33 import java.util.Map; | 33 import java.util.Map; |
34 import java.util.zip.ZipEntry; | |
35 import java.util.zip.ZipInputStream; | |
34 import java.util.zip.ZipOutputStream; | 36 import java.util.zip.ZipOutputStream; |
35 import java.util.zip.ZipEntry; | |
36 import luan.Luan; | 37 import luan.Luan; |
37 import luan.LuanState; | 38 import luan.LuanState; |
38 import luan.LuanTable; | 39 import luan.LuanTable; |
39 import luan.LuanFunction; | 40 import luan.LuanFunction; |
40 import luan.LuanJavaFunction; | 41 import luan.LuanJavaFunction; |
209 } catch(FileNotFoundException e) { | 210 } catch(FileNotFoundException e) { |
210 return false; | 211 return false; |
211 } | 212 } |
212 } | 213 } |
213 | 214 |
215 public void unzip(String path) throws IOException, LuanException { | |
216 ZipInputStream in = new ZipInputStream(new BufferedInputStream(inputStream())); | |
217 ZipEntry entry; | |
218 while( (entry = in.getNextEntry()) != null ) { | |
219 if( entry.isDirectory() ) | |
220 continue; | |
221 File file = new File(path,entry.getName()); | |
222 file.getParentFile().mkdirs(); | |
223 OutputStream out = new FileOutputStream(file); | |
224 Utils.copyAll(in,out); | |
225 out.close(); | |
226 } | |
227 in.close(); | |
228 } | |
229 | |
214 public LuanTable table() { | 230 public LuanTable table() { |
215 LuanTable tbl = new LuanTable(); | 231 LuanTable tbl = new LuanTable(); |
216 try { | 232 try { |
217 tbl.rawPut( "java", this ); | 233 tbl.rawPut( "java", this ); |
218 tbl.rawPut( "to_string", new LuanJavaFunction( | 234 tbl.rawPut( "to_string", new LuanJavaFunction( |
233 tbl.rawPut( "read_blocks", new LuanJavaFunction( | 249 tbl.rawPut( "read_blocks", new LuanJavaFunction( |
234 LuanIn.class.getMethod( "read_blocks", Integer.class ), this | 250 LuanIn.class.getMethod( "read_blocks", Integer.class ), this |
235 ) ); | 251 ) ); |
236 tbl.rawPut( "exists", new LuanJavaFunction( | 252 tbl.rawPut( "exists", new LuanJavaFunction( |
237 LuanIn.class.getMethod( "exists" ), this | 253 LuanIn.class.getMethod( "exists" ), this |
254 ) ); | |
255 tbl.rawPut( "unzip", new LuanJavaFunction( | |
256 LuanIn.class.getMethod( "unzip", String.class ), this | |
238 ) ); | 257 ) ); |
239 } catch(NoSuchMethodException e) { | 258 } catch(NoSuchMethodException e) { |
240 throw new RuntimeException(e); | 259 throw new RuntimeException(e); |
241 } | 260 } |
242 return tbl; | 261 return tbl; |