/*
 * Copyright (C) 2011 Thomas Akehurst
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.github.tomakehurst.wiremock.common;

import com.google.common.io.ByteStreams;

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;

public class BinaryFile {

    private URI uri;

    public BinaryFile(URI uri) {
        this.uri = uri;
    }

    public byte[] readContents() {
        InputStream stream = null;
        try {
            stream = uri.toURL().openStream();
            return ByteStreams.toByteArray(stream);
        } catch (final IOException ioe) {
            throw new RuntimeException(ioe);
        } finally {
            closeStream(stream);
        }
    }

    /**
     * @param stream Stream to close, may be null
     */
    private void closeStream(InputStream stream) {
        if (stream != null) {
            try {
                stream.close();
            } catch (IOException ioe) {
                throw new RuntimeException(ioe);
            }
        }
    }

    public String name() {
        return uri.toString();
    }

    @Override
    public String toString() {
        return name();
    }
}

@@ -788,20 +788,17 @@
 File %7B%0A%0A
-    
+%09
 private 
@@ -807,20 +807,17 @@
 I uri;%0A%0A
-    
+%09
 public B
@@ -837,24 +837,18 @@
  uri) %7B%0A
-        
+%09%09
 this.uri
@@ -855,27 +855,21 @@
  = uri;%0A
-    %7D%0A%0A    
+%09%7D%0A%0A%09
 public b
@@ -891,24 +891,18 @@
 nts() %7B%0A
-        
+%09%09
 InputStr
@@ -924,34 +924,19 @@
 ll;%0A
-        try %7B%0A            
+%09%09try %7B%0A%09%09%09
 stre
@@ -966,28 +966,19 @@
 ream();%0A
-            
+%09%09%09
 return B
@@ -1009,24 +1009,18 @@
 tream);%0A
-        
+%09%09
 %7D catch 
@@ -1045,28 +1045,19 @@
  ioe) %7B%0A
-            
+%09%09%09
 throw ne
@@ -1081,24 +1081,18 @@
 n(ioe);%0A
-        
+%09%09
 %7D finall
@@ -1095,28 +1095,19 @@
 nally %7B%0A
-            
+%09%09%09
 closeStr
@@ -1123,37 +1123,22 @@
 m);%0A
-        %7D%0A    %7D%0A%0A    /**%0A    
+%09%09%7D%0A%09%7D%0A%0A%09/**%0A%09
  * @
@@ -1183,20 +1183,14 @@
 ull%0A
-     */%0A    
+%09 */%0A%09
 priv
@@ -1232,24 +1232,18 @@
 ream) %7B%0A
-        
+%09%09
 if (stre
@@ -1260,42 +1260,21 @@
 ) %7B%0A
-            try %7B%0A                
+%09%09%09try %7B%0A%09%09%09%09
 stre
@@ -1285,28 +1285,19 @@
 lose();%0A
-            
+%09%09%09
 %7D catch 
@@ -1320,24 +1320,12 @@
 ) %7B%0A
-                
+%09%09%09%09
 thro
@@ -1357,43 +1357,22 @@
 e);%0A
-            %7D%0A        %7D%0A    %7D%0A%0A    
+%09%09%09%7D%0A%09%09%7D%0A%09%7D%0A%0A%09
 publ
@@ -1386,32 +1386,26 @@
 ng name() %7B%0A
-        
+%09%09
 return uri.t
@@ -1419,19 +1419,13 @@
 ();%0A
-    %7D%0A%0A    
+%09%7D%0A%0A%09
 @Ove
@@ -1430,20 +1430,17 @@
 verride%0A
-    
+%09
 public S
@@ -1462,16 +1462,10 @@
 ) %7B%0A
-        
+%09%09
 retu
@@ -1479,12 +1479,9 @@
 ();%0A
-    
+%09
 %7D%0A%7D%0A

Change formatting (tabs)