public CrailNodeType getType() { return fileInfo.getType(); }
public CrailInputStream getDirectInputStream(long readHint) throws Exception{ if (fileInfo.getType().isDirectory()){ throw new Exception("Cannot open stream for directory"); } return super.getInputStream(readHint); }
public synchronized CrailOutputStream getDirectOutputStream(long writeHint) throws Exception { if (fileInfo.getType().isDirectory()){ throw new Exception("Cannot open stream for directory"); } if (fileInfo.getToken() == 0){ throw new Exception("File is in read mode, cannot create outputstream, fd " + fileInfo.getFd()); } if (!outputStreams.tryAcquire()){ throw new Exception("Only one concurrent output stream per file allowed"); } return super.getOutputStream(writeHint); }
public static CoreNode create(CoreFileSystem fs, FileInfo fileInfo, String path) { if (fileInfo.getType().isContainer()){ return new CoreDirectory(fs, fileInfo, path); } else { return new CoreFile(fs, fileInfo, path); } }
public void setFileInfo(FileInfo fileInfo){ this.fd = fileInfo.getFd(); this.type = fileInfo.getType(); this.dirOffset = fileInfo.getDirOffset(); this.capacity.set(fileInfo.getCapacity()); this.token = fileInfo.getToken(); this.modificationTime = fileInfo.getModificationTime(); }
public DirectoryInputStream _listEntries(String name, boolean randomize) throws Exception { FileName directory = new FileName(name); if (CrailConstants.DEBUG){ LOG.info("getDirectoryList: " + name); } RpcGetFile fileRes = rpcConnection.getFile(directory, false).get(CrailConstants.RPC_TIMEOUT, TimeUnit.MILLISECONDS); if (fileRes.getError() != RpcErrors.ERR_OK) { LOG.info("getDirectoryList: " + RpcErrors.messages[fileRes.getError()]); throw new FileNotFoundException(RpcErrors.messages[fileRes.getError()]); } FileInfo dirInfo = fileRes.getFile(); if (!dirInfo.getType().isContainer()){ LOG.info("getDirectoryList: " + RpcErrors.messages[RpcErrors.ERR_FILE_IS_NOT_DIR]); throw new FileNotFoundException(RpcErrors.messages[RpcErrors.ERR_FILE_IS_NOT_DIR]); } CoreDirectory dirFile = new CoreDirectory(this, dirInfo, name); DirectoryInputStream inputStream = dirFile.getDirectoryInputStream(randomize); return inputStream; }
throw new IOException("createFile: " + RpcErrors.messages[RpcErrors.ERR_UNKNOWN]); if (fileInfo.getType() != type){ throw new IOException("createFile: " + "file type mismatch");