List of usage examples for org.apache.hadoop.io IOUtils closeStream
public static void closeStream(java.io.Closeable stream)
From source file:org.springframework.xd.batch.item.hadoop.HdfsTextItemWriter.java
License:Apache License
private void closeStream() { logger.debug("Closing output stream"); if (fsDataOutputStream != null) { try {//from w w w .jav a 2 s .c o m fsDataOutputStream.close(); } catch (IOException e) { IOUtils.closeStream(fsDataOutputStream); throw new StoreException("Error while closing stream", e); } finally { fsDataOutputStream = null; } } }
From source file:org.springframework.xd.batch.item.hadoop.SimpleHdfsTextItemWriter.java
License:Apache License
public void close() { if (fsDataOutputStream != null) { IOUtils.closeStream(fsDataOutputStream); } }
From source file:org.trafodion.sql.HBaseAccess.SequenceFileReader.java
License:Apache License
/** * Close the reader.//w w w. j ava 2s . c o m */ public String close() { lastError = ""; if (reader == null) { lastError = "open() was not called first."; return null; } IOUtils.closeStream(reader); return null; }
From source file:pl.edu.icm.coansys.commons.hadoop.SequenceFileUtils.java
License:Open Source License
public static List<DocumentWrapper> readDocWrappers(String inputFileUri) { List<DocumentWrapper> docWrappers = Lists.newArrayList(); SequenceFile.Reader reader = null; try {// ww w . j a v a2s . c o m Configuration conf = new Configuration(); reader = getSequenceFileReader(inputFileUri, conf); Writable key = (Writable) ReflectionUtils.newInstance(reader.getKeyClass(), conf); Writable value = (Writable) ReflectionUtils.newInstance(reader.getValueClass(), conf); while (reader.next(key, value)) { DocumentWrapper docWrapper = DocumentProtos.DocumentWrapper .parseFrom(((BytesWritable) value).copyBytes()); docWrappers.add(docWrapper); } } catch (IOException e) { } finally { IOUtils.closeStream(reader); } return docWrappers; }
From source file:pl.edu.icm.coansys.commons.hadoop.SequenceFileUtils.java
License:Open Source License
public static List<String> readTexts(String inputFileUri) { List<String> texts = Lists.newArrayList(); SequenceFile.Reader reader = null; try {/*from w w w .j ava2 s . com*/ Configuration conf = new Configuration(); reader = getSequenceFileReader(inputFileUri, conf); Writable key = (Writable) ReflectionUtils.newInstance(reader.getKeyClass(), conf); Writable value = (Writable) ReflectionUtils.newInstance(reader.getValueClass(), conf); while (reader.next(key, value)) { texts.add(((Text) value).toString()); } } catch (IOException e) { } finally { IOUtils.closeStream(reader); } return texts; }
From source file:pl.edu.icm.coansys.commons.hadoop.SequenceFileUtils.java
License:Open Source License
public static List<Pair<String, String>> readTextPairs(String inputFileUri) { List<Pair<String, String>> texts = Lists.newArrayList(); SequenceFile.Reader reader = null; try {//from w w w.ja v a2s .com Configuration conf = new Configuration(); reader = getSequenceFileReader(inputFileUri, conf); Writable key = (Writable) ReflectionUtils.newInstance(reader.getKeyClass(), conf); Writable value = (Writable) ReflectionUtils.newInstance(reader.getValueClass(), conf); while (reader.next(key, value)) { texts.add(new Pair<>(((Text) key).toString(), ((Text) value).toString())); } } catch (IOException e) { } finally { IOUtils.closeStream(reader); } return texts; }
From source file:pl.edu.icm.coansys.commons.hadoop.SequenceFileUtils.java
License:Open Source License
public static void formatAndPrintToConsole(String inputFileUri) throws IOException { SequenceFile.Reader reader = null; try {/* ww w .j av a 2 s .co m*/ Configuration conf = new Configuration(); reader = getSequenceFileReader(inputFileUri, conf); SequenceFile.Reader.bufferSize(250000); Writable key = (Writable) ReflectionUtils.newInstance(reader.getKeyClass(), conf); Writable value = (Writable) ReflectionUtils.newInstance(reader.getValueClass(), conf); while (reader.next(key, value)) { DocumentWrapper docWrapper = DocumentProtos.DocumentWrapper .parseFrom(((BytesWritable) value).copyBytes()); out.println(format(key, docWrapper)); } } finally { IOUtils.closeStream(reader); } }
From source file:pl.edu.icm.coansys.disambiguation.author.MacroExtractor.java
License:Open Source License
public static LinkedList<String> extract(String filename, String name) throws FileNotFoundException, IOException { LinkedList<String> script = new LinkedList<String>(); boolean isMacroFound = false; boolean isMacroEnded = false; FileReader fr = null;/*w w w .ja v a 2 s . c o m*/ BufferedReader in = null; try { fr = new FileReader(filename); in = new BufferedReader(fr); String line; while ((line = in.readLine()) != null) { if (line.startsWith("DEFINE " + name + "(")) { isMacroFound = true; } else if (line.equals("};") && isMacroFound) { isMacroEnded = true; break; } else if (isMacroFound) { script.add(line); } } } finally { IOUtils.closeStream(in); IOUtils.closeStream(fr); } if (!(isMacroFound && isMacroEnded)) { throw new RuntimeException("Cannot find the begining and the end of the macro: " + name); } return script; }
From source file:pl.edu.icm.coansys.disambiguation.author.MacroExtractor.java
License:Open Source License
public static LinkedList<String> extract(String filename, String name, Boolean includeHeader) throws FileNotFoundException, IOException { LinkedList<String> script = new LinkedList<String>(); boolean isMacroFound = false; boolean isMacroEnded = false; FileReader fr = null;// w ww .j a v a 2 s . c o m BufferedReader in = null; try { fr = new FileReader(filename); in = new BufferedReader(fr); String line; while ((line = in.readLine()) != null) { if (line.startsWith("DEFINE " + name + "(")) { if (includeHeader) { script.add(line); } isMacroFound = true; } else if (line.equals("};") && isMacroFound) { if (includeHeader) { script.add(line); } isMacroEnded = true; break; } else if (isMacroFound) { script.add(line); } } } finally { IOUtils.closeStream(in); IOUtils.closeStream(fr); } if (!(isMacroFound && isMacroEnded)) { throw new RuntimeException("Cannot find the begining and the end of the macro: " + name); } return script; }
From source file:pl.edu.icm.coansys.disambiguation.author.MacroExtractor.java
License:Open Source License
public static LinkedList<String> extract(String filename) throws FileNotFoundException, IOException { LinkedList<String> script = new LinkedList<String>(); FileReader fr = null;//from w ww . j a v a 2s. c om BufferedReader in = null; try { fr = new FileReader(filename); in = new BufferedReader(fr); String line; while ((line = in.readLine()) != null) { script.add(line); } } finally { IOUtils.closeStream(in); IOUtils.closeStream(fr); } return script; }