FileUtil.java
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
00003  * All rights reserved. This program is made available under the terms of the
00004  * Eclipse Public License v1.0 which accompanies this distribution, and is
00005  * available at http://www.eclipse.org/legal/epl-v10.html
00006  * Contributors:
00007  * General Robotix Inc.
00008  * National Institute of Advanced Industrial Science and Technology (AIST) 
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         // log のクリア
00080         String[] com;
00081         if (System.getProperty("os.name").equals("Linux") || System.getProperty("os.name").equals("Mac OS X")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
00082             com = new String[] { "/bin/sh", "-c", "rm " + logPath + File.separator + "*" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
00083         } else {
00084             logPath = logPath.replaceFirst("^\"", "");
00085             logPath = logPath.replaceFirst("\"$", "");
00086             com = new String[] { "cmd", "/c", "del " + "\"" + logPath + File.separator + "omninames-*.*" + "\""}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$
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 }


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sun Apr 2 2017 03:43:53