/** Opens an OutputStream to a file called file. * @param file File to open. * @return OutputStream of the file */ public static OutputStream writeFileStream(File file) throws IOException { return writeFileStream(file.getPath()); }
/** Opens an OutputStream to a file called file. * @param file File to open. * @return OutputStream of the file */ public static OutputStream writeFileStream(File file) throws IOException { return writeFileStream(file.getPath()); }
/** writeFSArrayFile * * @param filename * @return fixed size array file * @throws IOException */ public static ArrayFileWriter writeFSArrayFile(String filename) throws IOException { final DataOutputStream dos = new DataOutputStream(Files.writeFileStream(filename)); return new ArrayFileWriter() { public void write(Writable w) throws IOException { w.write(dos); } public void close() throws IOException { dos.close(); } }; }
/** writeFSArrayFile * * @param filename * @return fixed size array file * @throws IOException */ public static ArrayFileWriter writeFSArrayFile(String filename) throws IOException { final DataOutputStream dos = new DataOutputStream(Files.writeFileStream(filename)); return new ArrayFileWriter() { public void write(Writable w) throws IOException { w.write(dos); } public void close() throws IOException { dos.close(); } }; }
/** returns a utility class which can be used to write a FSOrderedMapFile. * Input data MUST be sorted by key. */ public static MapFileWriter mapFileWrite(final String filename) throws IOException { return new MapFileWriter(){ DataOutputStream out = new DataOutputStream(Files.writeFileStream(filename)); public void write(WritableComparable key, Writable value) throws IOException { //System.err.println("writing key "+ key.toString()); key.write(out); //System.err.println("writing value "+ value.toString()); value.write(out); } public void close() throws IOException { out.close(); } }; }
/** * Constructs an instance of the class for a given filename * @param filename java.lang.String the name of the underlying file * @throws java.io.IOException if an I/O error occurs */ public BitByteOutputStream(String filename) throws IOException { dos = new DataOutputStream(Files.writeFileStream(filename)); init(); }
/** returns a utility class which can be used to write a FSOrderedMapFile. * Input data MUST be sorted by key. */ public static MapFileWriter mapFileWrite(final String filename) throws IOException { return new MapFileWriter(){ DataOutputStream out = new DataOutputStream(Files.writeFileStream(filename)); public void write(WritableComparable key, Writable value) throws IOException { //System.err.println("writing key "+ key.toString()); key.write(out); //System.err.println("writing value "+ value.toString()); value.write(out); } public void close() throws IOException { out.close(); } }; }
/** * Constructs an instance of the class for a given file * @param file java.io.File the underlying file * @throws java.io.IOException if an I/O error occurs */ public BitByteOutputStream(File file) throws IOException { dos = new DataOutputStream(Files.writeFileStream(file)); init(); }
/** * Constructs an instance of the class for a given file * @param file java.io.File the underlying file * @throws java.io.IOException if an I/O error occurs */ public BitByteOutputStream(File file) throws IOException { dos = new DataOutputStream(Files.writeFileStream(file)); init(); }
/** * Constructs an instance of the class for a given filename * @param filename java.lang.String the name of the underlying file * @throws java.io.IOException if an I/O error occurs */ public BitByteOutputStream(String filename) throws IOException { dos = new DataOutputStream(Files.writeFileStream(filename)); init(); }
/** * Instanciates a RunWriter, given the filenames to write. * @param fileName name of the file to write the posting lists data. * @param termsFile name of the file to write the terms. * @throws IOException if an I/O error occurs. */ public RunWriter(String fileName, String termsFile) throws IOException{ bos = new BitOutputStream(fileName); stringDos = new DataOutputStream( Files.writeFileStream(termsFile)); this.info = "RunWriter("+fileName+")"; }
/** writes an entire map FSOrderedMapFile at once, to the specified filename, * and using the data contained in the specified iterator */ public static void mapFileWrite(String filename, Iterator<Entry<WritableComparable, Writable>> ti) throws IOException { DataOutputStream out = new DataOutputStream(Files.writeFileStream(filename)); while (ti.hasNext()) { Entry<WritableComparable, Writable> e = ti.next(); e.getKey().write(out); e.getValue().write(out); } out.close(); }
/** writes an entire map FSOrderedMapFile at once, to the specified filename, * and using the data contained in the specified iterator */ public static void mapFileWrite(String filename, Iterator<Entry<WritableComparable, Writable>> ti) throws IOException { DataOutputStream out = new DataOutputStream(Files.writeFileStream(filename)); while (ti.hasNext()) { Entry<WritableComparable, Writable> e = ti.next(); e.getKey().write(out); e.getValue().write(out); } out.close(); }
/** Copy a file from srcFile to destFile. * @return null if OK * @throws IOException if there was a problem copying */ public static Long copyFile(File srcFile, File destFile) throws IOException { return copyFile(openFileStream(srcFile), writeFileStream(destFile)); }
/** Copy a file from srcFile to destFile. * @return null if OK * @throws IOException if there was a problem copying */ public static Long copyFile(String srcFilename, String destFilename) throws IOException { return copyFile(openFileStream(srcFilename), writeFileStream(destFilename)); } /** Copy a file from srcFile to destFile.
/** Copy a file from srcFile to destFile. * @return null if OK * @throws IOException if there was a problem copying */ public static Long copyFile(String srcFilename, String destFilename) throws IOException { return copyFile(openFileStream(srcFilename), writeFileStream(destFilename)); } /** Copy a file from srcFile to destFile.
/** Copy a file from srcFile to destFile. * @return null if OK * @throws IOException if there was a problem copying */ public static Long copyFile(File srcFile, File destFile) throws IOException { return copyFile(openFileStream(srcFile), writeFileStream(destFile)); }
/** Write any dirty properties down to disk */ protected void flushProperties() throws IOException { if (dirtyProperties) { final String propertiesFilename = path + ApplicationSetup.FILE_SEPARATOR + prefix + PROPERTIES_SUFFIX; if ((Files.exists(propertiesFilename) && !Files .canWrite(propertiesFilename)) || (!Files.exists(propertiesFilename) && !Files .canWrite(path))) { logger.warn("Could not write to index properties at " + propertiesFilename + " because you do not have write permission on the index - some changes may be lost"); return; } final OutputStream outputStream = Files .writeFileStream(propertiesFilename); properties.store(outputStream, this.toString()); outputStream.close(); dirtyProperties = false; } }
public ByteOutputStream(String filename) throws IOException { OutputStream file; try{ file = Files.writeFileStream(filename); init(file); } catch(FileNotFoundException fnfe) { final String dir = Files.getParent(filename); logger.warn("Could not open new ByteOutputStream because it alleged file could not be found.", fnfe); if (logger.isDebugEnabled()) logger.debug("File.canRead()="+Files.canWrite(filename)+ "Dir.exists()=" +Files.exists(dir) + " Dir.canWrite()="+Files.canWrite(dir) +" Dir.contentsSize="+Files.list(dir).length); sleep(1000); if (logger.isDebugEnabled()) logger.debug("File.canRead()="+Files.canWrite(filename)+ "Dir.exists()=" +Files.exists(dir) + " Dir.canWrite()="+Files.canWrite(dir)+" Dir.contentsSize="+Files.list(dir).length); logger.warn("Retrying to write BitOutputStream."); init(Files.writeFileStream(filename)); logger.info("Previous warning can be ignored, BitOutputStream "+filename+" has opened successfully"); } }
public ByteOutputStream(String filename) throws IOException { OutputStream file; try{ file = Files.writeFileStream(filename); init(file); } catch(FileNotFoundException fnfe) { final String dir = Files.getParent(filename); logger.warn("Could not open new ByteOutputStream because it alleged file could not be found.", fnfe); if (logger.isDebugEnabled()) logger.debug("File.canRead()="+Files.canWrite(filename)+ "Dir.exists()=" +Files.exists(dir) + " Dir.canWrite()="+Files.canWrite(dir) +" Dir.contentsSize="+Files.list(dir).length); sleep(1000); if (logger.isDebugEnabled()) logger.debug("File.canRead()="+Files.canWrite(filename)+ "Dir.exists()=" +Files.exists(dir) + " Dir.canWrite()="+Files.canWrite(dir)+" Dir.contentsSize="+Files.list(dir).length); logger.warn("Retrying to write BitOutputStream."); init(Files.writeFileStream(filename)); logger.info("Previous warning can be ignored, BitOutputStream "+filename+" has opened successfully"); } }