Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00017 package com.generalrobotix.ui.util;
00018
00019 import java.io.*;
00020 import java.nio.channels.*;
00021 import com.generalrobotix.ui.GrxPluginManager;
00022 import com.generalrobotix.ui.grxui.Activator;
00023
00024 public class FileUtil {
00025
00035 public static void copyTransfer(String srcPath, String destPath)
00036 throws IOException {
00037
00038 FileChannel srcChannel = new FileInputStream(srcPath).getChannel();
00039 FileChannel destChannel = new FileOutputStream(destPath).getChannel();
00040 try {
00041 srcChannel.transferTo(0, srcChannel.size(), destChannel);
00042 } finally {
00043 srcChannel.close();
00044 destChannel.close();
00045 }
00046 }
00047
00056 public static void resourceToFile(Class<? extends GrxPluginManager> grxPluginManager, String srcName, File destFile)
00057 throws IOException {
00058 InputStream in = grxPluginManager.getResourceAsStream(srcName.toString());
00059 OutputStream out = new FileOutputStream(destFile.toString());
00060 try {
00061 byte[] buf = new byte[1024];
00062 int len;
00063 while ((len = in.read(buf)) > 0) {
00064 out.write(buf, 0, len);
00065 }
00066 } catch (IOException e) {
00067 e.printStackTrace();
00068 } finally {
00069 in.close();
00070 out.close();
00071 }
00072 }
00073
00077 public static void deleteNameServerLog(String logPath)
00078 {
00079
00080 String[] com;
00081 if (System.getProperty("os.name").equals("Linux") || System.getProperty("os.name").equals("Mac OS X")) {
00082 com = new String[] { "/bin/sh", "-c", "rm " + logPath + File.separator + "*" };
00083 } else {
00084 logPath = logPath.replaceFirst("^\"", "");
00085 logPath = logPath.replaceFirst("\"$", "");
00086 com = new String[] { "cmd", "/c", "del " + "\"" + logPath + File.separator + "omninames-*.*" + "\""};
00087 }
00088 try {
00089 Process pr = Runtime.getRuntime().exec(com);
00090 InputStream is = pr.getInputStream();
00091 BufferedReader br = new BufferedReader(new InputStreamReader(is));
00092 String line;
00093 pr.waitFor();
00094 while ((line = br.readLine()) != null) {
00095 System.out.println(line);
00096 }
00097 } catch (Exception e) {
00098 e.printStackTrace();
00099 }
00100 }
00101 }