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]; }
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 long length() { Metadata metadata=cache.get(getPath()); if(metadata != null) return metadata.length; return 0; }
void setLength(int new_length) { Metadata metadata=cache.get(getPath()); if(metadata != null) { metadata.length=new_length; metadata.setModificationTime(System.currentTimeMillis()); cache.put(getPath(), metadata, (short)-1, 0, false); } else System.err.println("metadata for " + getPath() + " not found !"); }
public boolean exists() { return cache.get(getPath()) != null; }
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; } }
protected void initMetadata() { Metadata metadata=cache.get(getPath()); if(metadata != null) this.chunk_size=metadata.getChunkSize(); }
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; }
public boolean isDirectory() { Metadata val=cache.get(getPath()); return val.isDirectory(); }
public boolean isFile() { Metadata val=cache.get(getPath()); return val.isFile(); }
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; }
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]; }
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; }
void setLength(int new_length) { Metadata metadata=cache.get(getPath()); if(metadata != null) { metadata.length=new_length; metadata.setModificationTime(System.currentTimeMillis()); cache.put(getPath(), metadata, (short)-1, 0, false); } else System.err.println("metadata for " + getPath() + " not found !"); }
public long length() { Metadata metadata=cache.get(getPath()); if(metadata != null) return metadata.length; return 0; }
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; } }
protected void initMetadata() { Metadata metadata=cache.get(getPath()); if(metadata != null) this.chunk_size=metadata.getChunkSize(); }