/*
 * Copyright 2009 the original author or authors.
 *
 * 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 org.gradle.configuration;

import org.gradle.groovy.scripts.ScriptSource;
import org.gradle.util.UncheckedException;
	
import java.net.URL;
import java.io.InputStreamReader;
import java.io.IOException;
	
/**
 * @author Hans Dockter
 */
public class ImportsReader {
	
	private String importsText;
	
    public String getImports() {
		if (importsText == null) {
			try {
				URL url = getClass().getResource("default-imports.txt");
				InputStreamReader reader = new InputStreamReader(url.openStream(), "UTF8");
			
				int bufferSize = 2048; // at time of writing, the file was about 1k so this should cover in one read
				StringBuilder imports = new StringBuilder(bufferSize);
				char[] chars = new char[bufferSize];
			
				int numRead = reader.read(chars, 0, bufferSize);
				while (numRead != -1) {
					imports.append(chars, 0, numRead);
					numRead = reader.read(chars, 0, bufferSize);
				}
			
				importsText = imports.toString();
			} catch (IOException e) {
				throw UncheckedException.asUncheckedException(e);
			}
		}
		
		return importsText;
    }

    public ScriptSource withImports(ScriptSource source) {
        return new ImportsScriptSource(source, this);
    }
}

@@ -735,17 +735,16 @@
 eption;%0A
-%09
 %0Aimport 
@@ -819,17 +819,16 @@
 eption;%0A
-%09
 %0A/**%0A * 
@@ -881,19 +881,21 @@
 eader %7B%0A
-%09%0A%09
+%0A    
 private 
@@ -914,17 +914,16 @@
 tsText;%0A
-%09
 %0A    pub
@@ -948,18 +948,24 @@
 rts() %7B%0A
-%09%09
+        
 if (impo
@@ -987,21 +987,42 @@
 ) %7B%0A
-%09%09%09try %7B%0A%09%09%09%09
+            try %7B%0A                
 URL 
@@ -1074,20 +1074,32 @@
 .txt%22);%0A
-%09%09%09%09
+                
 InputStr
@@ -1166,24 +1166,33 @@
 UTF8%22);%0A
-%09%09%09%0A%09%09%09%09
+%0A                
 int buff
@@ -1284,20 +1284,32 @@
 ne read%0A
-%09%09%09%09
+                
 StringBu
@@ -1355,20 +1355,32 @@
 rSize);%0A
-%09%09%09%09
+                
 char%5B%5D c
@@ -1408,24 +1408,33 @@
 rSize%5D;%0A
-%09%09%09%0A%09%09%09%09
+%0A                
 int numR
@@ -1474,20 +1474,32 @@
 rSize);%0A
-%09%09%09%09
+                
 while (n
@@ -1514,21 +1514,36 @@
 = -1) %7B%0A
-%09%09%09%09%09
+                    
 imports.
@@ -1573,13 +1573,28 @@
 d);%0A
-%09%09%09%09%09
+                    
 numR
@@ -1638,22 +1638,43 @@
 e);%0A
-%09%09%09%09%7D%0A%09%09%09%0A%09%09%09%09
+                %7D%0A%0A                
 impo
@@ -1703,19 +1703,28 @@
 ring();%0A
-%09%09%09
+            
 %7D catch 
@@ -1745,12 +1745,24 @@
 ) %7B%0A
-%09%09%09%09
+                
 thro
@@ -1811,22 +1811,41 @@
 e);%0A
-%09%09%09%7D%0A%09%09%7D%0A%09%09%0A%09%09
+            %7D%0A        %7D%0A%0A        
 retu

remove accidental tabs.