langtools/test/tools/javac/api/T6483788.java
author mikejwre
Wed, 09 Jun 2010 18:56:41 -0700
changeset 5634 895b66935810
parent 5520 86e4b9a9da40
child 27319 030080f03e4f
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3782
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
     1
/*
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3782
diff changeset
     2
 * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
3782
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
     4
 *
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
     8
 *
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    13
 * accompanied this code).
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    14
 *
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    18
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3782
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3782
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3782
diff changeset
    21
 * questions.
3782
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    22
 */
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    23
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    24
/*
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    25
 * @test
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    26
 * @bug 6483788
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    27
 * @summary DefaultFileManager.ZipFileObject.toUri() fails to escape space characters
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    28
 */
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    29
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    30
import java.io.*;
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    31
import java.net.*;
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    32
import java.util.Collections;
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    33
import java.util.jar.*;
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    34
import java.util.zip.*;
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    35
import javax.tools.*;
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    36
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    37
public class T6483788 {
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    38
    public static void main(String[] args) throws Exception {
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    39
        new T6483788().run();
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    40
    }
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    41
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    42
    void run() throws Exception {
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    43
        File jar = createJar();
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    44
        JavaCompiler c = ToolProvider.getSystemJavaCompiler();
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    45
        StandardJavaFileManager fm = c.getStandardFileManager(null, null, null);
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    46
        fm.setLocation(StandardLocation.CLASS_PATH, Collections.singleton(jar));
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    47
        JavaFileObject fo = fm.getJavaFileForInput(StandardLocation.CLASS_PATH, "dummy", JavaFileObject.Kind.CLASS);
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    48
        System.err.println("file: " + fo);
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    49
        URI uri = fo.toUri();
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    50
        System.err.println("uri: " + uri);
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    51
        if (uri.toString().contains(" "))
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    52
            throw new Exception("unexpected space character found");
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    53
    }
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    54
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    55
    File createJar() throws IOException {
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    56
        byte[] dummy_data = new byte[10];
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    57
        File f = new File("a b.jar");
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    58
        OutputStream out = new FileOutputStream(f);
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    59
        try {
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    60
            JarOutputStream jar = new JarOutputStream(out);
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    61
            jar.putNextEntry(new ZipEntry("dummy.class"));
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    62
            jar.write(dummy_data);
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    63
            jar.close();
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    64
        } finally {
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    65
            out.close();
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    66
        }
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    67
        return f;
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    68
    }
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    69
}
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents:
diff changeset
    70