1 // Copyright (c) 2016, the R8 project authors. Please see the AUTHORS file 2 // for details. All rights reserved. Use of this source code is governed by a 3 // BSD-style license that can be found in the LICENSE file. 4 package com.android.tools.r8.utils; 5 6 import com.google.common.io.ByteStreams; 7 import java.io.BufferedInputStream; 8 import java.io.File; 9 import java.io.FileInputStream; 10 import java.io.FileOutputStream; 11 import java.io.IOException; 12 import java.io.InputStream; 13 import java.util.jar.JarEntry; 14 import java.util.jar.JarOutputStream; 15 16 public class JarBuilder { buildJar(File[] files, File jarFile)17 public static void buildJar(File[] files, File jarFile) throws IOException { 18 JarOutputStream target = new JarOutputStream(new FileOutputStream(jarFile)); 19 for (File file : files) { 20 // Only use the file name in the JAR entry (classes.dex, classes2.dex, ...) 21 JarEntry entry = new JarEntry(file.getName()); 22 entry.setTime(file.lastModified()); 23 target.putNextEntry(entry); 24 InputStream in = new BufferedInputStream(new FileInputStream(file)); 25 ByteStreams.copy(in, target); 26 in.close(); 27 target.closeEntry(); 28 } 29 target.close(); 30 } 31 } 32