/** * Internal create routine. * * @param path Path. * @param overwrite Overwrite flag. * @return Output stream. */ private OutputStream create0(IgfsPath path, boolean overwrite) { File file = fileForPath(path); boolean exists = file.exists(); if (exists) { if (!overwrite) throw new IgfsPathAlreadyExistsException("Failed to create a file because it already exists: " + path); } else { File parent = file.getParentFile(); if (!mkdirs0(parent)) throw new IgfsException("Failed to create parent directory for file (underlying file system " + "returned false): " + path); } try { return new FileOutputStream(file); } catch (IOException e) { throw handleSecondaryFsError(e, "Failed to create file [path=" + path + ", overwrite=" + overwrite + ']'); } }
/** * Cast IO exception to IGFS exception. * * @param msg Error message. * @param e IO exception. * @return IGFS exception. */ public static IgfsException cast(String msg, IOException e) { if (e instanceof FileNotFoundException) return new IgfsPathNotFoundException(e); else if (e instanceof ParentNotDirectoryException) return new IgfsParentNotDirectoryException(msg, e); else if (e instanceof PathIsNotEmptyDirectoryException) return new IgfsDirectoryNotEmptyException(e); else if (e instanceof PathExistsException) return new IgfsPathAlreadyExistsException(msg, e); else return new IgfsException(msg, e); }
/** * @param errCode Error code. * @param err Error. * @throws IgniteCheckedException Based on error code. */ public static void throwError(Integer errCode, String err) throws IgniteCheckedException { assert err != null; assert errCode != -1; if (errCode == ERR_FILE_NOT_FOUND) throw new IgfsPathNotFoundException(err); else if (errCode == ERR_PATH_ALREADY_EXISTS) throw new IgfsPathAlreadyExistsException(err); else if (errCode == ERR_DIRECTORY_NOT_EMPTY) throw new IgfsDirectoryNotEmptyException(err); else if (errCode == ERR_PARENT_NOT_DIRECTORY) throw new IgfsParentNotDirectoryException(err); else if (errCode == ERR_INVALID_HDFS_VERSION) throw new IgfsInvalidHdfsVersionException(err); else if (errCode == ERR_CORRUPTED_FILE) throw new IgfsCorruptedFileException(err); else if (errCode == ERR_IGFS_GENERIC) throw new IgfsException(err); throw new IgniteCheckedException(err); }
throw fsException(new IgfsPathAlreadyExistsException("Failed to add file name into the destination " + " directory (file already exists) [fileId=" + fileId + ", destFileName=" + destFileName + ", destParentId=" + destParentId + ']'));
throw new IgfsPathAlreadyExistsException("Failed to perform move because destination points " + "to existing file [src=" + srcPath + ", dst=" + dstPath + ']'); throw new IgfsPathAlreadyExistsException("Failed to perform move because destination already " + "contains entry with the same name existing file [src=" + srcPath + ", dst=" + dstPath + ']');
throw new IgfsPathAlreadyExistsException("Failed to create a file: " + path);
/** * Internal create routine. * * @param path Path. * @param overwrite Overwrite flag. * @return Output stream. */ private OutputStream create0(IgfsPath path, boolean overwrite) { File file = fileForPath(path); boolean exists = file.exists(); if (exists) { if (!overwrite) throw new IgfsPathAlreadyExistsException("Failed to create a file because it already exists: " + path); } else { File parent = file.getParentFile(); if (!mkdirs0(parent)) throw new IgfsException("Failed to create parent directory for file (underlying file system " + "returned false): " + path); } try { return new FileOutputStream(file); } catch (IOException e) { throw handleSecondaryFsError(e, "Failed to create file [path=" + path + ", overwrite=" + overwrite + ']'); } }
/** * @param errCode Error code. * @param err Error. * @throws IgniteCheckedException Based on error code. */ public static void throwError(Integer errCode, String err) throws IgniteCheckedException { assert err != null; assert errCode != -1; if (errCode == ERR_FILE_NOT_FOUND) throw new IgfsPathNotFoundException(err); else if (errCode == ERR_PATH_ALREADY_EXISTS) throw new IgfsPathAlreadyExistsException(err); else if (errCode == ERR_DIRECTORY_NOT_EMPTY) throw new IgfsDirectoryNotEmptyException(err); else if (errCode == ERR_PARENT_NOT_DIRECTORY) throw new IgfsParentNotDirectoryException(err); else if (errCode == ERR_INVALID_HDFS_VERSION) throw new IgfsInvalidHdfsVersionException(err); else if (errCode == ERR_CORRUPTED_FILE) throw new IgfsCorruptedFileException(err); else if (errCode == ERR_IGFS_GENERIC) throw new IgfsException(err); throw new IgniteCheckedException(err); }
throw fsException(new IgfsPathAlreadyExistsException("Failed to add file name into the destination " + " directory (file already exists) [fileId=" + fileId + ", destFileName=" + destFileName + ", destParentId=" + destParentId + ']'));
throw new IgfsPathAlreadyExistsException("Failed to perform move because destination points " + "to existing file [src=" + srcPath + ", dst=" + dstPath + ']'); throw new IgfsPathAlreadyExistsException("Failed to perform move because destination already " + "contains entry with the same name existing file [src=" + srcPath + ", dst=" + dstPath + ']');
throw new IgfsPathAlreadyExistsException("Failed to create a file: " + path);