Search in sources :

Example 46 with JarOutputStream

use of java.util.jar.JarOutputStream in project buck by facebook.

the class CustomZipEntryTest method writeSimpleJarAndGetHash.

private HashCode writeSimpleJarAndGetHash() throws Exception {
    Path output = Files.createTempFile("example", ".jar");
    try (FileOutputStream fileOutputStream = new FileOutputStream(output.toFile());
        ZipOutputStream out = new JarOutputStream(fileOutputStream)) {
        ZipEntry entry = new CustomZipEntry("test");
        out.putNextEntry(entry);
        out.write(new byte[0]);
        entry = new ZipEntry("test1");
        entry.setTime(ZipConstants.getFakeTime());
        out.putNextEntry(entry);
        out.write(new byte[0]);
    }
    return Hashing.sha1().hashBytes(Files.readAllBytes(output));
}
Also used : Path(java.nio.file.Path) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) JarOutputStream(java.util.jar.JarOutputStream)

Example 47 with JarOutputStream

use of java.util.jar.JarOutputStream in project error-prone by google.

the class BoxedPrimitiveConstructorTest method incompleteClasspath.

@Test
public void incompleteClasspath() throws Exception {
    File libJar = tempFolder.newFile("lib.jar");
    try (FileOutputStream fis = new FileOutputStream(libJar);
        JarOutputStream jos = new JarOutputStream(fis)) {
        addClassToJar(jos, BoxedPrimitiveConstructorTest.class);
        addClassToJar(jos, Inner.class);
    }
    compilationHelper.addSourceLines("Test.java", "import " + Inner.class.getCanonicalName() + ";", "class Test {", "  void m() {", "    new Inner();", "  }", "}").setArgs(Arrays.asList("-cp", libJar.toString())).doTest();
}
Also used : FileOutputStream(java.io.FileOutputStream) JarOutputStream(java.util.jar.JarOutputStream) File(java.io.File) Test(org.junit.Test)

Example 48 with JarOutputStream

use of java.util.jar.JarOutputStream in project error-prone by google.

the class CheckReturnValueTest method noCRVonClasspath.

@Test
public void noCRVonClasspath() throws Exception {
    File libJar = tempFolder.newFile("lib.jar");
    try (FileOutputStream fis = new FileOutputStream(libJar);
        JarOutputStream jos = new JarOutputStream(fis)) {
        addClassToJar(jos, CRVTest.class);
        addClassToJar(jos, CheckReturnValueTest.class);
    }
    compilationHelper.addSourceLines("Test.java", "class Test {", "  void m() {", "    // BUG: Diagnostic contains: Ignored return value", "    com.google.errorprone.bugpatterns.CheckReturnValueTest.CRVTest.f();", "  }", "}").setArgs(Arrays.asList("-cp", libJar.toString())).doTest();
}
Also used : FileOutputStream(java.io.FileOutputStream) JarOutputStream(java.util.jar.JarOutputStream) File(java.io.File) Test(org.junit.Test)

Example 49 with JarOutputStream

use of java.util.jar.JarOutputStream in project error-prone by google.

the class FunctionalInterfaceClashTest method incompleteClasspath.

@Test
public void incompleteClasspath() throws Exception {
    File libJar = tempFolder.newFile("lib.jar");
    try (FileOutputStream fis = new FileOutputStream(libJar);
        JarOutputStream jos = new JarOutputStream(fis)) {
        addClassToJar(jos, getClass());
        addClassToJar(jos, Super.class);
    }
    testHelper.addSourceLines("Test.java", "import " + Super.class.getCanonicalName() + ";", "class Test extends Super {}").setArgs(Arrays.asList("-cp", libJar.toString())).doTest();
}
Also used : FileOutputStream(java.io.FileOutputStream) JarOutputStream(java.util.jar.JarOutputStream) File(java.io.File) Test(org.junit.Test)

Example 50 with JarOutputStream

use of java.util.jar.JarOutputStream in project error-prone by google.

the class JUnit4SetUpNotRunTest method noBeforeOnClasspath.

@Test
public void noBeforeOnClasspath() throws Exception {
    File libJar = tempFolder.newFile("lib.jar");
    try (FileOutputStream fis = new FileOutputStream(libJar);
        JarOutputStream jos = new JarOutputStream(fis)) {
        addClassToJar(jos, RunWith.class);
        addClassToJar(jos, JUnit4.class);
        addClassToJar(jos, BlockJUnit4ClassRunner.class);
        addClassToJar(jos, ParentRunner.class);
        addClassToJar(jos, SuperTest.class);
        addClassToJar(jos, SuperTest.class.getEnclosingClass());
    }
    compilationHelper.addSourceLines("Test.java", "import org.junit.runner.RunWith;", "import org.junit.runners.JUnit4;", "import " + SuperTest.class.getCanonicalName() + ";", "@RunWith(JUnit4.class)", "class Test extends SuperTest {", "  @Override public void setUp() {}", "}").setArgs(Arrays.asList("-cp", libJar.toString())).doTest();
}
Also used : FileOutputStream(java.io.FileOutputStream) JarOutputStream(java.util.jar.JarOutputStream) File(java.io.File) Test(org.junit.Test)

Aggregations

JarOutputStream (java.util.jar.JarOutputStream)485 FileOutputStream (java.io.FileOutputStream)308 File (java.io.File)265 JarEntry (java.util.jar.JarEntry)194 Manifest (java.util.jar.Manifest)140 IOException (java.io.IOException)130 ZipEntry (java.util.zip.ZipEntry)116 InputStream (java.io.InputStream)89 FileInputStream (java.io.FileInputStream)84 JarFile (java.util.jar.JarFile)82 ByteArrayOutputStream (java.io.ByteArrayOutputStream)76 ByteArrayInputStream (java.io.ByteArrayInputStream)55 Test (org.junit.Test)55 BufferedOutputStream (java.io.BufferedOutputStream)47 Path (java.nio.file.Path)42 JarInputStream (java.util.jar.JarInputStream)41 OutputStream (java.io.OutputStream)36 Attributes (java.util.jar.Attributes)36 ArrayList (java.util.ArrayList)35 Map (java.util.Map)27