test/org/openjdk/jigsaw/_RepositoryCatalog.java

Print this page




  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 // Compiled and invoked by repocat.sh
  25 
  26 import java.io.*;
  27 import java.util.*;
  28 import java.lang.module.*;
  29 import java.nio.*;
  30 import java.nio.channels.*;
  31 import org.openjdk.jigsaw.*;
  32 import org.openjdk.jigsaw.RepositoryCatalog.StreamedRepositoryCatalog;
  33 
  34 import static org.openjdk.jigsaw.Repository.ModuleType;
  35 import static org.openjdk.jigsaw.FileConstants.ModuleFile.HashType;
  36 
  37 
  38 public class _RepositoryCatalog {
  39 
  40     private static ModuleSystem ms = ModuleSystem.base();
  41 
  42     private static <T> boolean eq(Collection<T> c1, Collection<T> c2) {
  43         return c1.containsAll(c2) && c2.containsAll(c1);
  44     }
  45 
  46     static File CAT_FILE = new File("z.scat");
  47 
  48     static void writeStreamed(Map<ModuleId,byte[]> modules, String[] args)
  49         throws Exception
  50     {
  51         StreamedRepositoryCatalog rc = RepositoryCatalog.load(null);
  52         ByteBuffer bb = ByteBuffer.allocate(8192);
  53         for (int i = 0; i < args.length; i++) {
  54             bb.clear();
  55             try (FileChannel fc = new FileInputStream(args[i]).getChannel()) {
  56                 int s = (int)fc.size();
  57                 if (bb.capacity() < s)
  58                     bb = ByteBuffer.allocate(s);
  59                 int n = fc.read(bb);
  60                 if (n != s)
  61                     throw new IOException("Mis-sized read");
  62                 rc.add(ModuleType.JMOD, Arrays.copyOfRange(bb.array(), 0, n),

  63                        42, 93,
  64                        HashType.SHA256, new byte[0]);
  65                 modules.put(ms.parseModuleInfo(bb.array()).id(),
  66                             Arrays.copyOfRange(bb.array(), 0, n));
  67             }
  68         }
  69         try (OutputStream rco = new FileOutputStream(CAT_FILE)) {
  70             rc.store(rco);
  71         }
  72     }
  73 
  74     static StreamedRepositoryCatalog readStreamed(Map<ModuleId,byte[]> modules)
  75         throws Exception
  76     {
  77         InputStream in = new FileInputStream(CAT_FILE);
  78         StreamedRepositoryCatalog rc = null;
  79         try {
  80             rc = RepositoryCatalog.load(in);
  81         } finally {
  82             in.close();




  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 // Compiled and invoked by repocat.sh
  25 
  26 import java.io.*;
  27 import java.util.*;
  28 import java.lang.module.*;
  29 import java.nio.*;
  30 import java.nio.channels.*;
  31 import org.openjdk.jigsaw.*;
  32 import org.openjdk.jigsaw.RepositoryCatalog.StreamedRepositoryCatalog;
  33 
  34 import static org.openjdk.jigsaw.Repository.ModuleFileType;
  35 import static org.openjdk.jigsaw.FileConstants.ModuleFile.HashType;
  36 
  37 
  38 public class _RepositoryCatalog {
  39 
  40     private static ModuleSystem ms = ModuleSystem.base();
  41 
  42     private static <T> boolean eq(Collection<T> c1, Collection<T> c2) {
  43         return c1.containsAll(c2) && c2.containsAll(c1);
  44     }
  45 
  46     static File CAT_FILE = new File("z.scat");
  47 
  48     static void writeStreamed(Map<ModuleId,byte[]> modules, String[] args)
  49         throws Exception
  50     {
  51         StreamedRepositoryCatalog rc = RepositoryCatalog.load(null);
  52         ByteBuffer bb = ByteBuffer.allocate(8192);
  53         for (int i = 0; i < args.length; i++) {
  54             bb.clear();
  55             try (FileChannel fc = new FileInputStream(args[i]).getChannel()) {
  56                 int s = (int)fc.size();
  57                 if (bb.capacity() < s)
  58                     bb = ByteBuffer.allocate(s);
  59                 int n = fc.read(bb);
  60                 if (n != s)
  61                     throw new IOException("Mis-sized read");
  62                 rc.add(ModuleFileType.JMOD, ModuleArchitecture.ANY,
  63                        Arrays.copyOfRange(bb.array(), 0, n),
  64                        42, 93,
  65                        HashType.SHA256, new byte[0]);
  66                 modules.put(ms.parseModuleInfo(bb.array()).id(),
  67                             Arrays.copyOfRange(bb.array(), 0, n));
  68             }
  69         }
  70         try (OutputStream rco = new FileOutputStream(CAT_FILE)) {
  71             rc.store(rco);
  72         }
  73     }
  74 
  75     static StreamedRepositoryCatalog readStreamed(Map<ModuleId,byte[]> modules)
  76         throws Exception
  77     {
  78         InputStream in = new FileInputStream(CAT_FILE);
  79         StreamedRepositoryCatalog rc = null;
  80         try {
  81             rc = RepositoryCatalog.load(in);
  82         } finally {
  83             in.close();