comparison core/src/luan/modules/IoLuan.java @ 748:de2418d11786

minor
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 14 Jul 2016 21:09:55 -0600
parents d3a1e9a48a94
children 85f5444fb7d4
comparison
equal deleted inserted replaced
747:d3a1e9a48a94 748:de2418d11786
28 import java.net.Inet4Address; 28 import java.net.Inet4Address;
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.List;
33 import java.util.Map; 34 import java.util.Map;
34 import java.util.zip.ZipEntry; 35 import java.util.zip.ZipEntry;
35 import java.util.zip.ZipInputStream; 36 import java.util.zip.ZipInputStream;
36 import java.util.zip.ZipOutputStream; 37 import java.util.zip.ZipOutputStream;
37 import luan.Luan; 38 import luan.Luan;
329 330
330 public LuanTable binary_writer() throws IOException { 331 public LuanTable binary_writer() throws IOException {
331 return binaryWriter(new BufferedOutputStream(outputStream())); 332 return binaryWriter(new BufferedOutputStream(outputStream()));
332 } 333 }
333 334
334 public void zip(LuanState luan,String basePath,String... filePaths) throws LuanException, IOException { 335 public void zip(LuanState luan,String basePath,LuanTable filePathList) throws LuanException, IOException {
335 if( filePaths.length == 0 ) { 336 String[] filePaths;
337 if( filePathList==null ) {
336 File file = new File(basePath).getCanonicalFile(); 338 File file = new File(basePath).getCanonicalFile();
337 filePaths = new String[]{file.toString()}; 339 filePaths = new String[]{file.toString()};
338 basePath = file.getParent(); 340 basePath = file.getParent();
341 } else {
342 List list = filePathList.asList();
343 filePaths = new String[list.size()];
344 for( int i=0; i<filePaths.length; i++ ) {
345 Object obj = list.get(i);
346 if( !(obj instanceof String) )
347 throw new LuanException("file paths must be strings");
348 filePaths[i] = (String)obj;
349 }
339 } 350 }
340 if( !basePath.endsWith("/") ) 351 if( !basePath.endsWith("/") )
341 basePath += '/'; 352 basePath += '/';
342 ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(outputStream())); 353 ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(outputStream()));
343 zip(out,basePath,filePaths); 354 zip(out,basePath,filePaths);
377 ) ); 388 ) );
378 tbl.rawPut( "binary_writer", new LuanJavaFunction( 389 tbl.rawPut( "binary_writer", new LuanJavaFunction(
379 LuanIO.class.getMethod( "binary_writer" ), this 390 LuanIO.class.getMethod( "binary_writer" ), this
380 ) ); 391 ) );
381 tbl.rawPut( "zip", new LuanJavaFunction( 392 tbl.rawPut( "zip", new LuanJavaFunction(
382 LuanIO.class.getMethod( "zip", LuanState.class, String.class, new String[0].getClass() ), this 393 LuanIO.class.getMethod( "zip", LuanState.class, String.class, LuanTable.class ), this
383 ) ); 394 ) );
384 } catch(NoSuchMethodException e) { 395 } catch(NoSuchMethodException e) {
385 throw new RuntimeException(e); 396 throw new RuntimeException(e);
386 } 397 }
387 return tbl; 398 return tbl;