2222import java .io .InputStreamReader ;
2323import java .io .StringReader ;
2424import java .nio .charset .Charset ;
25- import java .nio .file .Files ;
26- import java .nio .file .Path ;
2725import java .nio .file .Paths ;
2826import java .util .logging .Logger ;
2927import java .util .stream .Collectors ;
3432import javax .xml .parsers .ParserConfigurationException ;
3533
3634import org .utplsql .sqldev .exception .GenericRuntimeException ;
35+ import org .utplsql .sqldev .model .FileTools ;
3736import org .utplsql .sqldev .model .XMLTools ;
3837import org .w3c .dom .Document ;
3938import org .w3c .dom .NodeList ;
@@ -66,26 +65,6 @@ public SnippetMerger(final File file) {
6665 userSnippetsFile = file ;
6766 }
6867
69- private byte [] readFile (Path path ) {
70- try {
71- return Files .readAllBytes (path );
72- } catch (IOException e ) {
73- final String msg = "Cannot read file " + path .toString () + " due to " + e .getMessage () + "." ;
74- logger .severe (() -> msg );
75- throw new GenericRuntimeException (msg , e );
76- }
77- }
78-
79- private void writeFile (Path path , byte [] bytes ) {
80- try {
81- Files .write (path , bytes );
82- } catch (IOException e ) {
83- final String msg = "Cannot write file " + path .toString () + " due to " + e .getMessage () + "." ;
84- logger .severe (() -> msg );
85- throw new GenericRuntimeException (msg , e );
86- }
87- }
88-
8968 private DocumentBuilder createDocumentBuilder () {
9069 DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance ();
9170 try {
@@ -112,7 +91,7 @@ public void merge() {
11291 String result = null ;
11392 if (userSnippetsFile .exists ()) {
11493 // file exists, proper merge required
115- final String userSnippets = new String (readFile (Paths .get (userSnippetsFile .getAbsolutePath ())));
94+ final String userSnippets = new String (FileTools . readFile (Paths .get (userSnippetsFile .getAbsolutePath ())));
11695 final DocumentBuilder docBuilder = createDocumentBuilder ();
11796 final Document userSnippetsDoc = parse (docBuilder , new InputSource (new StringReader (userSnippets )));
11897 final NodeList userSnippetsGroups = xmlTools .getNodeList (userSnippetsDoc ,
@@ -138,7 +117,7 @@ public void merge() {
138117 // just copy
139118 result = utplsqlSnippets ;
140119 }
141- writeFile (Paths .get (userSnippetsFile .getAbsolutePath ()), result .getBytes ());
120+ FileTools . writeFile (Paths .get (userSnippetsFile .getAbsolutePath ()), result .getBytes ());
142121 }
143122
144123 public String getTemplate () {
0 commit comments