?? mbeanhelper.java
字號:
/* * This file is part of MobiMon. * * MobiMon is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * MobiMon is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with MobiMon; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *//* * MBeanHelper.java * * Created on March 5, 2003, 8:26 AM */package mobimon.mbeans;import java.io.*;import java.nio.*;import java.nio.channels.*;import mobimon.common.*;/** * * @author jan */public class MBeanHelper { /** Creates a new instance of MBeanHelper */ public MBeanHelper() { } public static byte[] executeCommand(String command) { byte[] barr = null; Runtime rt = Runtime.getRuntime(); try { Process pr = rt.exec(command); StreamEater eatStdout = new StreamEater(pr.getInputStream()); StreamEater eatStderr = new StreamEater(pr.getErrorStream()); Thread out = new Thread(eatStdout); Thread err = new Thread(eatStderr); out.start(); err.start(); int retVal = pr.waitFor(); barr = (retVal == 0) ? eatStdout.getBytes() : eatStderr.getBytes(); } catch (Exception e) { System.out.println(e.getClass().getName() + ":" + e.getMessage()); barr = null; } return barr; } public static Page getFileContents(String fileName, int where) { byte[] fileContents = null; int pos = Math.abs(where); Page page = null; try { FileInputStream fis = new FileInputStream(fileName); FileChannel fc = fis.getChannel(); long fileSize = fc.size(); MappedByteBuffer mbb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fileSize); if (where > 0) { if ((pos * Page.SIZE) >= fileSize) { pos = (int)(fileSize / Page.SIZE); mbb.position(pos * Page.SIZE); pos = 0; } else { mbb.position(--pos * Page.SIZE); pos = where + 1; } } else if (where < 0) { if ((pos * Page.SIZE) >= fileSize) { mbb.position(0); pos = 0; } else { mbb.position((int)(fileSize - (pos * Page.SIZE))); pos = where - 1; } } else { pos = 0; mbb.position(0); } if (mbb.hasRemaining()) { fileContents = new byte[Math.min(mbb.remaining(), Page.SIZE)]; mbb.get(fileContents); } fc.close(); fis.close(); page = new Page(pos, fileContents); } catch (IOException ioe) { page = new Page(0, null); } return page; }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -