diff --git a/src/edu/stanford/nlp/ie/crf/CRFFeatureExporter.java b/src/edu/stanford/nlp/ie/crf/CRFFeatureExporter.java index 5a621e5fc2..f9834fc61b 100644 --- a/src/edu/stanford/nlp/ie/crf/CRFFeatureExporter.java +++ b/src/edu/stanford/nlp/ie/crf/CRFFeatureExporter.java @@ -18,8 +18,7 @@ /** * Exports CRF features for use with other programs. * Usage: CRFFeatureExporter -prop crfClassifierPropFile -trainFile inputFile -exportFeatures outputFile - * - Output file is automatically gzipped/b2zipped if ending in gz/bz2 - * - bzip2 requires that bzip2 is available via command line + * - Output file is automatically gzipped/b2zipped if ending in gz * - Currently exports features in a format that can be read by a modified crfsgd * (crfsgd assumes features are gzipped) * TODO: Support other formats (like crfsuite) diff --git a/src/edu/stanford/nlp/io/BZip2PipedOutputStream.java b/src/edu/stanford/nlp/io/BZip2PipedOutputStream.java deleted file mode 100644 index 5f83e9876b..0000000000 --- a/src/edu/stanford/nlp/io/BZip2PipedOutputStream.java +++ /dev/null @@ -1,68 +0,0 @@ -package edu.stanford.nlp.io; -import edu.stanford.nlp.util.logging.Redwood; - -import edu.stanford.nlp.util.ByteStreamGobbler; -import edu.stanford.nlp.util.RuntimeInterruptedException; -import edu.stanford.nlp.util.StreamGobbler; - -import java.io.*; - -/** -* Opens a outputstream for writing into a bzip2 file by piping into the bzip2 command. -* Output from bzip2 command is written into the specified file. -* -* @author Angel Chang -*/ -public class BZip2PipedOutputStream extends OutputStream -{ - private String filename; - private Process process; - private ByteStreamGobbler outGobbler; - private StreamGobbler errGobbler; - private PrintWriter errWriter; - - public BZip2PipedOutputStream(String filename) throws IOException { - this(filename, System.err); - } - - public BZip2PipedOutputStream(String filename, OutputStream err) throws IOException { - String bzip2 = System.getProperty("bzip2", "bzip2"); - String cmd = bzip2; // + " > " + filename; - //log.info("getBZip2PipedOutputStream: Running command: "+cmd); - ProcessBuilder pb = new ProcessBuilder(); - pb.command(cmd); - this.process = pb.start(); - this.filename = filename; - OutputStream outStream = new FileOutputStream(filename); - errWriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(err))); - outGobbler = new ByteStreamGobbler("Output stream gobbler: " + cmd + " " + filename, - process.getInputStream(), outStream); - errGobbler = new StreamGobbler(process.getErrorStream(), errWriter); - outGobbler.start(); - errGobbler.start(); - } - - public void flush() throws IOException - { - process.getOutputStream().flush(); - } - - public void write(int b) throws IOException - { - process.getOutputStream().write(b); - } - - public void close() throws IOException - { - process.getOutputStream().close(); - try { - outGobbler.join(); - errGobbler.join(); - outGobbler.getOutputStream().close(); - process.waitFor(); - } catch (InterruptedException ex) { - throw new RuntimeInterruptedException(ex); - } - //log.info("getBZip2PipedOutputStream: Closed. "); - } -} diff --git a/src/edu/stanford/nlp/io/IOUtils.java b/src/edu/stanford/nlp/io/IOUtils.java index f121ecd169..578a28ddf2 100644 --- a/src/edu/stanford/nlp/io/IOUtils.java +++ b/src/edu/stanford/nlp/io/IOUtils.java @@ -1488,7 +1488,7 @@ public static LinkedList readCSVStrictly(String filename, int numColum } /** - * Get a input file stream (automatically gunzip/bunzip2 depending on file extension) + * Get a input file stream (automatically gunzip depending on file extension) * @param filename Name of file to open * @return Input stream that can be used to read from the file * @throws IOException if there are exceptions opening the file @@ -1497,15 +1497,12 @@ public static InputStream getFileInputStream(String filename) throws IOException InputStream in = new FileInputStream(filename); if (filename.endsWith(".gz")) { in = new GZIPInputStream(in); - } else if (filename.endsWith(".bz2")) { - //in = new CBZip2InputStream(in); - in = getBZip2PipedInputStream(filename); } return in; } /** - * Get a output file stream (automatically gzip/bzip2 depending on file extension) + * Get a output file stream (automatically gzip depending on file extension) * @param filename Name of file to open * @return Output stream that can be used to write to the file * @throws IOException if there are exceptions opening the file @@ -1514,9 +1511,6 @@ public static OutputStream getFileOutputStream(String filename) throws IOExcepti OutputStream out = new FileOutputStream(filename); if (filename.endsWith(".gz")) { out = new GZIPOutputStream(out); - } else if (filename.endsWith(".bz2")) { - //out = new CBZip2OutputStream(out); - out = getBZip2PipedOutputStream(filename); } return out; } @@ -1525,9 +1519,6 @@ public static OutputStream getFileOutputStream(String filename, boolean append) OutputStream out = new FileOutputStream(filename, append); if (filename.endsWith(".gz")) { out = new GZIPOutputStream(out); - } else if (filename.endsWith(".bz2")) { - //out = new CBZip2OutputStream(out); - out = getBZip2PipedOutputStream(filename); } return out; } @@ -1584,22 +1575,6 @@ public static PrintWriter getPrintWriter(String filename, String encoding) throw return new PrintWriter(new BufferedWriter(new OutputStreamWriter(out, encoding)), true); } - public static InputStream getBZip2PipedInputStream(String filename) throws IOException { - String bzcat = System.getProperty("bzcat", "bzcat"); - Runtime rt = Runtime.getRuntime(); - String cmd = bzcat + " " + filename; - //log.info("getBZip2PipedInputStream: Running command: "+cmd); - Process p = rt.exec(cmd); - Writer errWriter = new BufferedWriter(new OutputStreamWriter(System.err)); - StreamGobbler errGobbler = new StreamGobbler(p.getErrorStream(), errWriter); - errGobbler.start(); - return p.getInputStream(); - } - - public static OutputStream getBZip2PipedOutputStream(String filename) throws IOException { - return new BZip2PipedOutputStream(filename); - } - private static final Pattern tab = Pattern.compile("\t"); /**