Code example for JarEntry

0
    { 
        final File zf = File.createTempFile("deletetemp", ".jar");
        zf.deleteOnExit();
        JarOutputStream jos = new JarOutputStream(
                new FileOutputStream(zf));
        JarEntry je = new JarEntry("entry");
        jos.putNextEntry(je);
        jos.write("hello, world".getBytes("ASCII"));
        jos.close();
 
        HttpServer server = HttpServer.create(
                new InetSocketAddress((InetAddress) null, 0), 0);
        HttpContext context = server.createContext("/",
            new HttpHandler() { 
                public void handle(HttpExchange e) { 
                try { 
                    FileInputStream fis = new FileInputStream(zf); 
                    e.sendResponseHeaders(200, zf.length()); 
                    OutputStream os = e.getResponseBody(); 
                    byte[] buf = new byte[1024];