import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.jar.Attributes;
import java.util.jar.Manifest;

public class Scratch {
  public static void main(String[] args) throws IOException {
    // Create empty manifest
    Manifest manifest = new Manifest();
    Attributes mainAttributes = manifest.getMainAttributes();
    mainAttributes.put(Attributes.Name.MANIFEST_VERSION, "1.0");
    // Add a key which leads to an invalid manifest
    // (found exactly like that in a Maven POM, quite difficult to debug!)
    mainAttributes.put(
      new Attributes.Name("Bundle-Copyright"),
      "(C) Copyright 1999-2001 Xerox Corporation,\n" +
        "\t\t\t\t\t\t\t\t\t\t\t\t2002 Palo Alto Research Center, Incorporated (PARC),\n" +
        "\t\t\t\t\t\t\t\t\t\t\t\t2003-2019 Contributors. All Rights Reserved"
    );
    // Dump invalid manifest to console - please note the fatal blank line consisting only of tabs
    manifest.write(System.out);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    manifest.write(out);
    // Read invalid manifest -> "IOException: invalid header field (line 3)"
    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    new Manifest(in);
  }
} 