Changeset 26190


Ignore:
Timestamp:
09/13/12 12:00:12 (9 years ago)
Author:
jmt12
Message:

Moving the StreamGobbler - used in both plugins to prevent a full STDERR buffer killing the import - into it's own class... my computer doesn't have an issue with exactly the same class occuring twice, but Medusa's one seems stricter in this regard

Location:
gs2-extensions/video-and-audio/trunk/src/opt/Terrier
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • gs2-extensions/video-and-audio/trunk/src/opt/Terrier/ImageDocument.java

    r26186 r26190  
    1717package org.terrier.indexing;
    1818
    19 import java.io.BufferedOutputStream;
    20 import java.io.BufferedReader;
    21 import java.io.FileOutputStream;
    2219import java.io.InputStream;
    23 import java.io.InputStreamReader;
    24 import java.io.IOException;
    25 import java.io.PrintWriter;
    2620import java.io.StringReader;
    2721import java.io.Reader;
    28 import java.lang.Thread;
    2922import java.nio.file.Files;
    3023import java.nio.file.Path;
     
    3629
    3730import org.apache.log4j.Logger;
     31import org.terrier.indexing.StreamGobbler;
    3832import org.terrier.indexing.tokenisation.TokenStream;
    3933import org.terrier.indexing.tokenisation.Tokeniser;
     
    260254}
    261255
    262 class StreamGobbler
    263 extends Thread
    264 {
    265   InputStream is;
    266   String file_path;
    267   boolean output_to_file;
    268 
    269   StreamGobbler(InputStream is)
    270   {
    271     this.is = is;
    272     this.output_to_file = false;
    273   }
    274 
    275   StreamGobbler(InputStream is, String file_path)
    276   {
    277     this.is = is;
    278     this.file_path = file_path;
    279     this.output_to_file = true;
    280   }
    281 
    282   public void run()
    283   {
    284     try
    285     {
    286       InputStreamReader isr = new InputStreamReader(is);
    287       BufferedReader br = new BufferedReader(isr);
    288       String line = null;
    289       if (output_to_file)
    290       {
    291         PrintWriter pw = new PrintWriter(new BufferedOutputStream(new FileOutputStream(file_path)));
    292         while ( (line = br.readLine()) != null)
    293         {
    294           pw.println(line);
    295         }
    296         pw.flush();
    297         pw.close();
    298       }
    299       else
    300       {
    301         while ( (line  = br.readLine()) != null)
    302         {
    303           // Do nothing - equivalent to > /dev/null
    304         }
    305       }
    306     }
    307     catch (IOException ioe)
    308     {
    309       ioe.printStackTrace();
    310     }
    311   }
    312 }
  • gs2-extensions/video-and-audio/trunk/src/opt/Terrier/VideoDocument.java

    r26186 r26190  
    1717package org.terrier.indexing;
    1818
    19 import java.io.BufferedOutputStream;
    2019import java.io.BufferedReader;
    2120import java.io.File;
    22 import java.io.FileOutputStream;
    2321import java.io.InputStream;
    2422import java.io.InputStreamReader;
    2523import java.io.IOException;
    26 import java.io.PrintWriter;
    2724import java.io.StringReader;
    2825import java.io.Reader;
     
    4340
    4441import org.apache.log4j.Logger;
     42import org.terrier.indexing.StreamGobbler;
    4543import org.terrier.indexing.tokenisation.TokenStream;
    4644import org.terrier.indexing.tokenisation.Tokeniser;
     
    392390  /** getReader() **/
    393391}
    394 
    395 class StreamGobbler
    396 extends Thread
    397 {
    398   InputStream is;
    399   String file_path;
    400   boolean output_to_file;
    401 
    402   StreamGobbler(InputStream is)
    403   {
    404     this.is = is;
    405     this.output_to_file = false;
    406   }
    407 
    408   StreamGobbler(InputStream is, String file_path)
    409   {
    410     this.is = is;
    411     this.file_path = file_path;
    412     this.output_to_file = true;
    413   }
    414 
    415   public void run()
    416   {
    417     try
    418     {
    419       InputStreamReader isr = new InputStreamReader(is);
    420       BufferedReader br = new BufferedReader(isr);
    421       String line = null;
    422       if (output_to_file)
    423       {
    424         PrintWriter pw = new PrintWriter(new BufferedOutputStream(new FileOutputStream(file_path)));
    425         while ( (line = br.readLine()) != null)
    426         {
    427           pw.println(line);
    428         }
    429         pw.flush();
    430         pw.close();
    431       }
    432       else
    433       {
    434         while ( (line  = br.readLine()) != null)
    435         {
    436           // Do nothing - equivalent to > /dev/null
    437         }
    438       }
    439     }
    440     catch (IOException ioe)
    441     {
    442       ioe.printStackTrace();
    443     }
    444   }
    445 }
    446 
Note: See TracChangeset for help on using the changeset viewer.