예제 #1
0
 /**
  * {@inheritDoc}
  *
  * @see
  *     com.continuent.tungsten.common.file.FileIO#getInputStream(com.continuent.tungsten.common.file.FilePath)
  */
 public FileInputStream getInputStream(FilePath path) throws FileIOException {
   try {
     File f = new File(path.toString());
     return new FileInputStream(f);
   } catch (IOException e) {
     throw new FileIOException("Unable to read data from file: file=" + path.toString(), e);
   }
 }
예제 #2
0
 /**
  * {@inheritDoc}
  *
  * @see
  *     com.continuent.tungsten.common.file.FileIO#getOutputStream(com.continuent.tungsten.common.file.FilePath)
  */
 public FileOutputStream getOutputStream(FilePath path) throws FileIOException {
   try {
     File f = new File(path.toString());
     return (new FileOutputStream(f));
   } catch (IOException e) {
     throw new FileIOException("Unable to write data to file: file=" + path.toString(), e);
   }
 }
예제 #3
0
 /**
  * {@inheritDoc}
  *
  * @see
  *     com.continuent.tungsten.common.file.FileIO#write(com.continuent.tungsten.common.file.FilePath,
  *     java.lang.String, java.lang.String, boolean)
  */
 @Override
 public void write(FilePath path, String value, String charset, boolean fsync)
     throws FileIOException {
   // Write the value and flush to storage. This overwrites any
   // previous version.
   FileOutputStream fos = null;
   try {
     fos = getOutputStream(path);
     BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos, charset));
     bw.write(value);
     bw.flush();
     if (fsync) {
       fos.getFD().sync();
     }
   } catch (IOException e) {
     throw new FileIOException(
         "Unable to write data to file: file="
             + path.toString()
             + " value="
             + safeSynopsis(value, 20),
         e);
   } finally {
     if (fos != null) {
       try {
         fos.close();
       } catch (IOException e) {
       }
     }
   }
 }
예제 #4
0
 /**
  * {@inheritDoc}
  *
  * @see
  *     com.continuent.tungsten.common.file.FileIO#list(com.continuent.tungsten.common.file.FilePath,
  *     java.lang.String)
  */
 @Override
 public String[] list(FilePath path, String prefix) {
   // Children can only exist on directories.
   if (isDirectory(path)) {
     File dir = new File(path.toString());
     String[] seqnoFileNames = dir.list(new LocalFilenameFilter(prefix));
     return seqnoFileNames;
   } else {
     return new String[0];
   }
 }
예제 #5
0
  /**
   * {@inheritDoc}
   *
   * @see
   *     com.continuent.tungsten.common.file.FileIO#delete(com.continuent.tungsten.common.file.FilePath,
   *     boolean)
   */
  @Override
  public boolean delete(FilePath path, boolean recursive) {
    // If the node does not exist, return immediately.
    if (!exists(path)) return true;

    // Try to delete children if this is recursive. Otherwise,
    // we cannot continuent and must return.
    if (isDirectory(path)) {
      for (String child : list(path)) {
        if (recursive) {
          boolean deleted = delete(new FilePath(path, child), recursive);
          if (!deleted) return false;
        } else return false;
      }
    }

    // Delete the path for which we were called.
    File fileToDelete = new File(path.toString());
    return fileToDelete.delete();
  }
예제 #6
0
 /**
  * {@inheritDoc}
  *
  * @see
  *     com.continuent.tungsten.common.file.FileIO#read(com.continuent.tungsten.common.file.FilePath,
  *     java.lang.String)
  */
 @Override
 public String read(FilePath path, String charset) throws FileIOException {
   // Read from storage.
   FileInputStream fos = null;
   try {
     fos = getInputStream(path);
     BufferedReader bf = new BufferedReader(new InputStreamReader(fos, charset));
     StringBuffer buf = new StringBuffer();
     int nextChar = 0;
     while ((nextChar = bf.read()) > -1) {
       buf.append((char) nextChar);
     }
     return buf.toString();
   } catch (IOException e) {
     throw new FileIOException("Unable to read data from file: file=" + path.toString(), e);
   } finally {
     if (fos != null) {
       try {
         fos.close();
       } catch (IOException e) {
       }
     }
   }
 }
예제 #7
0
 /**
  * {@inheritDoc}
  *
  * @see
  *     com.continuent.tungsten.common.file.FileIO#readable(com.continuent.tungsten.common.file.FilePath)
  */
 @Override
 public boolean readable(FilePath path) {
   return new File(path.toString()).canRead();
 }
예제 #8
0
 /**
  * {@inheritDoc}
  *
  * @see
  *     com.continuent.tungsten.common.file.FileIO#writable(com.continuent.tungsten.common.file.FilePath)
  */
 @Override
 public boolean writable(FilePath path) {
   return new File(path.toString()).canWrite();
 }
예제 #9
0
 /**
  * {@inheritDoc}
  *
  * @see
  *     com.continuent.tungsten.common.file.FileIO#isDirectory(com.continuent.tungsten.common.file.FilePath)
  */
 @Override
 public boolean isDirectory(FilePath path) {
   return new File(path.toString()).isDirectory();
 }
예제 #10
0
 /**
  * {@inheritDoc}
  *
  * @see
  *     com.continuent.tungsten.common.file.FileIO#exists(com.continuent.tungsten.common.file.FilePath)
  */
 @Override
 public boolean exists(FilePath path) {
   return new File(path.toString()).exists();
 }
예제 #11
0
 /**
  * {@inheritDoc}
  *
  * @see
  *     com.continuent.tungsten.common.file.FileIO#mkdirs(com.continuent.tungsten.common.file.FilePath)
  */
 @Override
 public boolean mkdirs(FilePath path) {
   return new File(path.toString()).mkdirs();
 }