01: /*
02: * To change this template, choose Tools | Templates
03: * and open the template in the editor.
04: */
05: package org.netbeans.modules.etlbulkloader.tools;
06:
07: import org.netbeans.modules.etlbulkloader.packager.*;
08: import java.io.File;
09: import java.io.FileInputStream;
10: import java.io.FileOutputStream;
11: import java.io.IOException;
12: import net.java.hulp.i18n.Logger;
13: import org.netbeans.modules.etl.logger.Localizer;
14: import org.netbeans.modules.etl.logger.LogUtil;
15:
16: /**
17: *
18: * @author Manish
19: */
20: public class ETLBLUtils {
21:
22: private static transient final Logger mLogger = LogUtil
23: .getLogger(ETLBLUtils.class.getName());
24: private static transient final Localizer mLoc = Localizer.get();
25:
26: public static boolean checkIfPackageExists(String absPackagePath,
27: boolean createIfNotExists) {
28: File testpackage = new File(absPackagePath);
29: if (testpackage.exists()) {
30: if (testpackage.isDirectory()) {
31: return true;
32: } else {
33: mLogger.infoNoloc(mLoc.t("Package : " + absPackagePath
34: + " is not a dir"));
35: return false;
36: }
37: } else {
38: // Create this package
39: if (createIfNotExists) {
40: mLogger.infoNoloc(mLoc.t("Package : " + absPackagePath
41: + " does not exist. Creating ...."));
42: boolean status = testpackage.mkdir();
43: if (status) {
44: return true;
45: } else {
46: mLogger.infoNoloc(mLoc.t("Unable to create dir : "
47: + absPackagePath));
48: return false;
49: }
50: } else {
51: mLogger.infoNoloc(mLoc.t("Package : " + absPackagePath
52: + " does not exist."));
53: return false;
54: }
55: }
56: }
57:
58: public static void copyFile(String srcFileAbsPath, String trgtDir) {
59: FileInputStream fis = null;
60: FileOutputStream fos = null;
61: try {
62:
63: File input = new File(srcFileAbsPath);
64: String srcfilename = input.getName();
65: File output = new File(trgtDir + ETLBLPkgConstants.fs
66: + srcfilename);
67:
68: //in = new FileReader(input);
69: //out = new FileWriter(output);
70: fis = new FileInputStream(input);
71: fos = new FileOutputStream(output);
72: byte[] buf = new byte[1024];
73: /*
74: int c;
75: while ((c = in.read()) != -1) {
76: out.write(c);
77: }
78: */
79: int i = 0;
80: while ((i = fis.read(buf)) != -1) {
81: fos.write(buf, 0, i);
82: }
83:
84: } catch (IOException ex) {
85: mLogger.errorNoloc(mLoc.t("PRSR031: Exception :{0}", ex
86: .getMessage()), ex);
87: } finally {
88: try {
89: //in.close();
90: //out.close();
91: fis.close();
92: fos.close();
93: } catch (IOException ex) {
94: mLogger.errorNoloc(mLoc.t("PRSR032: Exception :{0}", ex
95: .getMessage()), ex);
96: }
97: }
98: }
99: }
|