/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.ocelotds;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Writer;
import javax.inject.Inject;
import org.ocelotds.logger.OcelotLogger;
import org.slf4j.Logger;

/**
 *
 * @author hhfrancois
 */
public abstract class AbstractServiceProvider implements IServicesProvider {

	@Inject
	@OcelotLogger
	private Logger logger;

	protected abstract String getJsFilename();
	
	@Override
	public void streamJavascriptServices(Writer writer) {
		InputStream injs = this.getClass().getClassLoader().getResourceAsStream(getJsFilename());
		try (BufferedReader in = new BufferedReader(new InputStreamReader(injs, Constants.UTF_8))) {
			String inputLine;
			while ((inputLine = in.readLine()) != null) {
				writer.write(inputLine);
				writer.write(Constants.BACKSLASH_N);
			}
		} catch(IOException ex) {
			logger.error("Generation of '"+getJsFilename()+"' failed.", ex);
		}
	}
	
}

@@ -230,40 +230,8 @@
 %0D%0A%0D%0A
-import java.io.BufferedReader;%0D%0A
 impo
@@ -291,34 +291,35 @@
 %0Aimport java.io.
-In
+Out
 putStreamReader;
@@ -315,38 +315,8 @@
 ream
-Reader;%0D%0Aimport java.io.Writer
 ;%0D%0Ai
@@ -685,28 +685,36 @@
 ces(
-Writer writer
+OutputStream out
 ) %7B%0D%0A%09%09
+try (
 Inpu
@@ -723,18 +723,16 @@
 tream in
-js
  = this.
@@ -799,174 +799,126 @@
 e())
-;
+) %7B
 %0D%0A%09%09
+%09
-try (BufferedReader in = new BufferedReader(new InputStreamReader(injs, Constants.UTF_8))) %7B%0D%0A%09%09%09String inputLine;%0D%0A%09%09%09while ((inputLine = in.readLine()) != null
+byte%5B%5D buffer = new byte%5BConstants.DEFAULT_BUFFER_SIZE%5D;%0D%0A%09%09%09int n = 0;%0D%0A%09%09%09while (-1 != (n = in.read(buffer))
 ) %7B%0D
@@ -926,72 +926,30 @@
 %09%09%09%09
-writer
+out
 .write(
-inputLine);%0D%0A%09%09%09%09writer.write(Constants.BACKSLASH_N
+buffer, 0, n
 );%0D%0A

use Outputstreamrather than writer