001: package isql;
002:
003: import java.io.*;
004: import java.util.*;
005: import util.*;
006: import javax.swing.JTable;
007: import javax.swing.KeyStroke;
008:
009: /** utilities specific to this application.
010: * @author Rahul Kumar $Author: rahul_kumar $
011: * $Id: IsqlUtil.java,v 1.4 2004/01/01 06:52:48 rahul_kumar Exp $
012: */
013: public class IsqlUtil {
014: /** reads up a files contents into a String and returns the same.
015: */
016: public static String getFileContents(String filename)
017: throws java.io.IOException, java.io.FileNotFoundException {
018:
019: StringBuffer sb = new StringBuffer(512);
020: String line = null;
021: BufferedReader br = new BufferedReader(new FileReader(filename));
022: while ((line = br.readLine()) != null)
023: sb.append(line).append('\n');
024:
025: return sb.toString();
026: }
027:
028: /** return contents of a file, between given linenumbers inclusive.
029: */
030: public static String getFileContents(String filename, int linefrom,
031: int lineto) throws java.io.IOException,
032: java.io.FileNotFoundException {
033:
034: StringBuffer sb = new StringBuffer(512);
035: String line = null;
036: LineNumberReader br = new LineNumberReader(new FileReader(
037: filename));
038: while ((line = br.readLine()) != null) {
039: if (br.getLineNumber() < linefrom)
040: continue;
041: if (br.getLineNumber() > lineto)
042: break;
043: sb.append(line).append('\n');
044: }
045:
046: return sb.toString();
047: } // getFileContents with line range
048:
049: /** utility function should go out of here */
050: public static StringBuffer printVector(List mVect) {
051: int msize = mVect.size();
052: StringBuffer sb = new StringBuffer(128);
053: for (int i = 0; i < msize; i++) {
054: if (mVect.get(i) != null)
055: sb.append(mVect.get(i).toString()).append('\n');
056: else
057: sb.append("null \n");
058: }
059: return sb;
060: }
061:
062: public static StringBuffer printVector(List mVect, int width) {
063: StringBuffer sb = new StringBuffer(128);
064: int msize = mVect.size();
065: for (int i = 0; i < msize; i++) {
066: if (mVect.get(i) != null)
067: sb.append(mVect.get(i).toString()).append(" | ");
068: else
069: sb.append("null | ");
070:
071: if (i % width == 0)
072: sb.append(" |\n");
073: }
074: sb.append('\n');
075: return sb;
076: }
077:
078: public static StringBuffer printVector(List[] mVect, String name) {
079: StringBuffer sb = new StringBuffer(128);
080: List vcol = mVect[0];
081: List vrow = mVect[1];
082: int csize = vcol.size();
083: sb.append(name).append('\n');
084: for (int i = 0; i < csize; i++) {
085: if (vcol.get(i) != null)
086: sb.append(vcol.get(i).toString()).append(" | ");
087: else
088: sb.append("null | ");
089: }
090: sb.append('\n');
091: for (int i = 0; i < csize; i++) {
092: if (vrow.get(i) != null)
093: sb.append(vrow.get(i).toString()).append(" | ");
094: else
095: sb.append("null | ");
096: }
097: sb.append('\n');
098: return sb;
099: } // printvector
100:
101: /** executes the given command and returns the output in a string.
102: * command and its arguments to come in string array. this uses
103: * exec(String[]) method of java.lang.Runtime class.
104: */
105:
106: public static String getExecOutput(String[] command)
107: throws java.io.IOException {
108: Process pr = Runtime.getRuntime().exec(command);
109: BufferedReader in = new BufferedReader(new InputStreamReader(pr
110: .getInputStream()));
111: String line = "";
112: StringBuffer t = new StringBuffer(128);
113: while ((line = in.readLine()) != null)
114: t.append(line).append('\n');
115: return t.toString();
116: }
117:
118: public static void main(String args[]) {
119: try {
120: if (args.length > 0) {
121: System.out.println(getExecOutput(args));
122: }
123: } catch (Exception exc) {
124: System.err.println("EXC:" + exc.toString());
125: }
126: }
127:
128: } // class
|