samples/exceptions/test/org/apidesign/exceptions/trycatchredo/MemoryURL.java
changeset 310 fba31e9504a1
parent 308 7f38f014244c
     1.1 --- a/samples/exceptions/test/org/apidesign/exceptions/trycatchredo/MemoryURL.java	Sun Feb 01 13:27:04 2009 +0100
     1.2 +++ b/samples/exceptions/test/org/apidesign/exceptions/trycatchredo/MemoryURL.java	Sun Feb 01 16:03:37 2009 +0100
     1.3 @@ -39,18 +39,16 @@
     1.4      }
     1.5      
     1.6      private static Map<String,InputStream> contents = new HashMap<String,InputStream>();
     1.7 -    private static Map<String,MC> outputs = new HashMap<String,MC>();
     1.8 -    public static void registerURL(String u, String content, ByteArrayOutputStream out) throws MalformedURLException {
     1.9 +    private static Map<String,OutputStream> outputs = new HashMap<String,OutputStream>();
    1.10 +    public static void registerURL(String u, String content, OutputStream out) throws MalformedURLException {
    1.11          contents.put(u, new ByteArrayInputStream(content.getBytes()));
    1.12 -        if (out != null) {
    1.13 -            new MC(new URL(u)).out = out;
    1.14 -        }
    1.15 +        outputs.put(u, out);
    1.16      }
    1.17      
    1.18 -    public static byte[] getOutputForURL(String u) {
    1.19 -        MC out = outputs.get(u);
    1.20 +    public static String getOutputForURL(String u) {
    1.21 +        OutputStream out = outputs.get(u);
    1.22          Assert.assertNotNull("No output for " + u, out);
    1.23 -        return out.out.toByteArray();
    1.24 +        return out.toString();
    1.25      }
    1.26      
    1.27      protected URLConnection openConnection(URL u) throws IOException {
    1.28 @@ -59,11 +57,15 @@
    1.29      
    1.30      private static final class MC extends URLConnection {
    1.31          private InputStream values;
    1.32 -        private ByteArrayOutputStream out;
    1.33 +        private OutputStream out;
    1.34          
    1.35          public MC(URL u) {
    1.36              super(u);
    1.37 -            outputs.put(u.toExternalForm(), this);
    1.38 +            out = outputs.get(u.toExternalForm());
    1.39 +            if (out == null) {
    1.40 +                out = new ByteArrayOutputStream();
    1.41 +                outputs.put(u.toExternalForm(), out);
    1.42 +            }
    1.43          }
    1.44  
    1.45          public void connect() throws IOException {