public File[] listFiles(FilenameFilter filter) { return _listFiles(filter); }
public boolean createNewFile() throws IOException { if(exists()) return true; if(!checkParentDirs(getPath(), false)) return false; cache.put(getPath(), new Metadata(0, System.currentTimeMillis(), chunk_size, Metadata.FILE), (short)-1, 0, true); return true; }
public boolean mkdirs() { try { boolean parents_exist=checkParentDirs(getPath(), true); if(!parents_exist) return false; cache.put(getPath(), new Metadata(0, System.currentTimeMillis(), chunk_size, Metadata.DIR), (short)-1, 0, true); return true; } catch(IOException e) { return false; } }
public boolean delete(boolean synchronous) { if(!exists()) return false; if(isFile()) { fs.remove(getPath(), synchronous); // removes all the chunks belonging to the file cache.remove(getPath(), synchronous); // removes the metadata information return true; } if(isDirectory()) { File[] files=listFiles(); if(files != null && files.length > 0) return false; fs.remove(getPath(), synchronous); // removes all the chunks belonging to the file cache.remove(getPath(), synchronous); // removes the metadata information } return true; }
protected String[] _list(Object filter) { Cache<String, ReplCache.Value<Metadata>> internal_cache=cache.getL2Cache(); Set<String> keys=internal_cache.getInternalMap().keySet(); if(keys == null) return null; Collection<String> list=new ArrayList<>(keys.size()); for(String str: keys) { if(isChildOf(getPath(), str)) { if(filter instanceof FilenameFilter && !((FilenameFilter)filter).accept(new File(name), filename(str))) continue; else if(filter instanceof FileFilter && !((FileFilter)filter).accept(new File(str))) continue; list.add(str); } } String[] retval=new String[list.size()]; int index=0; for(String tmp: list) retval[index++]=tmp; return retval; }
GridOutputStream(GridFile file, boolean append, ReplCache<String,byte[]> cache, short repl_count, int chunk_size) throws FileNotFoundException { this.file=file; this.name=file.getPath(); this.cache=cache; this.repl_count=repl_count; this.chunk_size=chunk_size; current_buffer=new byte[chunk_size]; }
public File getFile(String pathname, int chunk_size) { return new GridFile(pathname, metadata, chunk_size, this); }
public boolean delete() { return delete(false); // asynchronous delete by default }
public OutputStream getOutput(GridFile file) throws IOException { if(!file.createNewFile()) throw new IOException("creation of " + file + " failed"); return new GridOutputStream(file, false, data, default_repl_count, default_chunk_size); }
public InputStream getInput(String pathname) throws FileNotFoundException { GridFile file=(GridFile)getFile(pathname); if(!file.exists()) throw new FileNotFoundException(pathname); return new GridInputStream(file, data, default_chunk_size); }
public String[] list(FilenameFilter filter) { return _list(filter); }
private static String print(File file, boolean details, int indent) { StringBuilder sb=new StringBuilder(); if(file.isDirectory()) { if(details) sb.append(indent(indent)); sb.append(file.getName()).append("/"); } else { if(details) sb.append(indent(indent)); sb.append(file.getName()); if(details) { sb.append(" " + Util.printBytes(file.length())); if(file instanceof GridFile) sb.append(", chunk_sise=" + ((GridFile)file).getChunkSize()); } } sb.append(details? '\n' : ' '); return sb.toString(); }
public boolean delete(boolean synchronous) { if(!exists()) return false; if(isFile()) { fs.remove(getPath(), synchronous); // removes all the chunks belonging to the file cache.remove(getPath(), synchronous); // removes the metadata information return true; } if(isDirectory()) { File[] files=listFiles(); if(files != null && files.length > 0) return false; fs.remove(getPath(), synchronous); // removes all the chunks belonging to the file cache.remove(getPath(), synchronous); // removes the metadata information } return true; }
protected String[] _list(Object filter) { Cache<String, ReplCache.Value<Metadata>> internal_cache=cache.getL2Cache(); Set<String> keys=internal_cache.getInternalMap().keySet(); if(keys == null) return null; Collection<String> list=new ArrayList<>(keys.size()); for(String str: keys) { if(isChildOf(getPath(), str)) { if(filter instanceof FilenameFilter && !((FilenameFilter)filter).accept(new File(name), filename(str))) continue; else if(filter instanceof FileFilter && !((FileFilter)filter).accept(new File(str))) continue; list.add(str); } } String[] retval=new String[list.size()]; int index=0; for(String tmp: list) retval[index++]=tmp; return retval; }
GridInputStream(GridFile file, ReplCache<String, byte[]> cache, int chunk_size) throws FileNotFoundException { this.file=file; this.name=file.getPath(); this.cache=cache; this.chunk_size=chunk_size; }
public boolean mkdir() { try { boolean parents_exist=checkParentDirs(getPath(), false); if(!parents_exist) return false; cache.put(getPath(), new Metadata(0, System.currentTimeMillis(), chunk_size, Metadata.DIR), (short)-1, 0, true); return true; } catch(IOException e) { e.printStackTrace(); return false; } }
public File getFile(String parent, String child, int chunk_size) { return new GridFile(parent, child, metadata, chunk_size, this); }