package com.flytxt.tp;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Utils {

	public String readLptemplate(String name) throws Exception {
		try {
			String valueOf = new String(findFile(name));
			return valueOf;
		} catch (Exception e) {
			throw e;
		}
	}

	public static String replaceWithConsoleStore(String absProcessor) {
		Pattern p = Pattern.compile("(new\\s)+(.+)(Store\\()", Pattern.MULTILINE);
		Matcher m = p.matcher(absProcessor);
		if (m.find())
			return m.replaceAll("$1 Console$3");
		return absProcessor;
	}

	private byte[] findFile(String name) throws URISyntaxException {
		InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream(name);
		try (ByteArrayOutputStream os = new ByteArrayOutputStream();) {
			byte[] buffer = new byte[0xFFFF];
			for (int len; (len = resourceAsStream.read(buffer)) != -1;)
				os.write(buffer, 0, len);

			os.flush();
			return os.toByteArray();
		} catch (IOException e) {
			e.printStackTrace();
			throw new URISyntaxException(name, e.getMessage());
		}
	}
}

@@ -753,16 +753,21 @@
 ion %7B%0A%09%09
+try (
 InputStr
@@ -846,21 +846,18 @@
 ame);%0A%09%09
-try (
+%09%09
 ByteArra
@@ -907,16 +907,17 @@
 m();) %7B%0A
+%0A
 %09%09%09byte%5B

Remove resource leak