public abstract DataInputStream getFileObject(URI fileUri, int start, int limit) throws CatalogIOException;
public DataInputStream getFileObject(URI studyUri, String objectId, int start, int limit) throws CatalogIOException { URI fileUri = getFileUri(studyUri, objectId); return getFileObject(fileUri, start, limit); }
/** * @param sourceIOManager Source IOManager * @param source Source file * @param targetIOManager Target IOManager * @param target Target file * @throws IOException * @throws org.opencb.opencga.catalog.exceptions.CatalogIOException */ private void copy(CatalogIOManager sourceIOManager, URI source, CatalogIOManager targetIOManager, URI target) throws IOException, CatalogIOException { logger.info("Copying file from {} to {}", source, target); //If it's the same IOManager, copy intra FS if (sourceIOManager == targetIOManager) { sourceIOManager.copyFile(source, target); return; } //TODO: Implement copies inter FS // HDFS -> POSIX // POSIX -> HDFS logger.info("Unable to copy directly from {} to {} . Doing manual copy.", source.getScheme(), target.getScheme()); DataInputStream fileObject = sourceIOManager.getFileObject(source, -1, -1); targetIOManager.createFile(target, fileObject); //throw new CatalogIOManagerException("Unable to copy from " + source.getScheme() + " to " + target.getScheme()); }
public DataInputStream download(String studyStr, String fileStr, int start, int limit, QueryOptions options, String sessionId) throws CatalogException { MyResource<File> resource = getUid(fileStr, studyStr, sessionId); authorizationManager.checkFilePermission(resource.getStudy().getUid(), resource.getResource().getUid(), resource.getUser(), FileAclEntry.FilePermissions.DOWNLOAD); URI fileUri = getUri(resource.getResource()); return catalogIOManagerFactory.get(fileUri).getFileObject(fileUri, start, limit); }
@Test public void testCreateFile() throws CatalogException, IOException { String content = "This is the content\tof the file"; try { fileManager.create(studyFqn3, File.Type.FILE, File.Format.UNKNOWN, File.Bioformat.UNKNOWN, "data/test/myTest/myFile.txt", null, null, new File.FileStatus(File.FileStatus.READY), 0, -1, null, -1, null, null, false, "This is the content\tof the file", null, sessionIdUser2); fail("An error should be raised because parents is false"); } catch (CatalogException e) { System.out.println("Correct"); } QueryResult<File> fileQueryResult = fileManager.create(studyFqn3, File.Type.FILE, File.Format.UNKNOWN, File.Bioformat.UNKNOWN, "data/test/myTest/myFile.txt", null, null, new File.FileStatus(File.FileStatus.READY), 0, -1, null, -1, null, null, true, content, null, sessionIdUser2); CatalogIOManager ioManager = catalogManager.getCatalogIOManagerFactory().get(fileQueryResult.first().getUri()); assertTrue(ioManager.exists(fileQueryResult.first().getUri())); DataInputStream fileObject = ioManager.getFileObject(fileQueryResult.first().getUri(), -1, -1); assertEquals(content, fileObject.readLine()); }