Mercurial Hosting > luan
comparison core/src/luan/modules/IoLuan.java @ 706:30c87c859277
add Io.zip
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 17 May 2016 19:00:25 -0600 |
parents | 52ecb629a634 |
children | 63cda9eec9a0 |
comparison
equal
deleted
inserted
replaced
705:52ecb629a634 | 706:30c87c859277 |
---|---|
27 import java.net.InetAddress; | 27 import java.net.InetAddress; |
28 import java.net.MalformedURLException; | 28 import java.net.MalformedURLException; |
29 import java.net.UnknownHostException; | 29 import java.net.UnknownHostException; |
30 import java.util.List; | 30 import java.util.List; |
31 import java.util.ArrayList; | 31 import java.util.ArrayList; |
32 import java.util.Map; | |
33 import java.util.zip.ZipOutputStream; | |
34 import java.util.zip.ZipEntry; | |
32 import luan.Luan; | 35 import luan.Luan; |
33 import luan.LuanState; | 36 import luan.LuanState; |
34 import luan.LuanTable; | 37 import luan.LuanTable; |
35 import luan.LuanFunction; | 38 import luan.LuanFunction; |
36 import luan.LuanJavaFunction; | 39 import luan.LuanJavaFunction; |
710 return null; | 713 return null; |
711 } | 714 } |
712 } | 715 } |
713 | 716 |
714 | 717 |
718 // files maps zip name to uri | |
719 public static void zip(LuanState luan,String zipUri,LuanTable files) throws LuanException, IOException { | |
720 Object obj = uri(luan,zipUri).rawGet("java"); | |
721 if( !(obj instanceof LuanIO) ) | |
722 throw new LuanException("invalid uri for zip"); | |
723 LuanIO zipIo = (LuanIO)obj; | |
724 ZipOutputStream out = new ZipOutputStream(zipIo.outputStream()); | |
725 for( Map.Entry<Object,Object> entry : files.iterable(luan) ) { | |
726 obj = entry.getKey(); | |
727 if( !(obj instanceof String) ) | |
728 throw new LuanException("zip file table keys must be strings"); | |
729 String fileName = (String)obj; | |
730 obj = entry.getValue(); | |
731 if( !(obj instanceof String) ) | |
732 throw new LuanException("zip file table values must be strings"); | |
733 String uriStr = (String)obj; | |
734 out.putNextEntry(new ZipEntry(fileName)); | |
735 obj = uri(luan,uriStr).rawGet("java"); | |
736 if( !(obj instanceof LuanIn) ) | |
737 throw new LuanException("invalid uri for zip"); | |
738 LuanIn zipIn = (LuanIn)obj; | |
739 InputStream in = zipIn.inputStream(); | |
740 Utils.copyAll(in,out); | |
741 in.close(); | |
742 out.closeEntry(); | |
743 } | |
744 out.close(); | |
745 } | |
746 | |
747 | |
715 // security | 748 // security |
716 | 749 |
717 public interface Security { | 750 public interface Security { |
718 public void check(LuanState luan,String name) throws LuanException; | 751 public void check(LuanState luan,String name) throws LuanException; |
719 } | 752 } |