@Test public void testWrite() throws Exception { final ProtocolFactory factory = new ProtocolFactory(new HashSet<>(Collections.singleton(new IRODSProtocol()))); final Profile profile = new ProfilePlistReader(factory).read( new Local("../profiles/iRODS (iPlant Collaborative).cyberduckprofile")); final Host host = new Host(profile, profile.getDefaultHostname(), new Credentials( System.getProperties().getProperty("irods.key"), System.getProperties().getProperty("irods.secret") )); final IRODSSession session = new IRODSSession(host); session.open(Proxy.DIRECT, new DisabledHostKeyCallback(), new DisabledLoginCallback()); session.login(Proxy.DIRECT, new DisabledLoginCallback(), new DisabledCancelCallback()); final Path test = new Path(new IRODSHomeFinderService(session).find(), UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); assertFalse(session.getFeature(Find.class).find(test)); final byte[] content = new RandomStringGenerator.Builder().build().generate(100).getBytes(); { final TransferStatus status = new TransferStatus(); status.setAppend(false); status.setLength(content.length); assertFalse(new IRODSWriteFeature(session).append(test, status.getLength(), PathCache.empty()).append); assertEquals(0L, new IRODSWriteFeature(session).append(test, status.getLength(), PathCache.empty()).size, 0L); final StatusOutputStream<Integer> out = new IRODSWriteFeature(session).write(test, status, new DisabledConnectionCallback()); assertNotNull(out); assertNotNull(out.getStatus()); new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), out); assertTrue(session.getFeature(Find.class).find(test)); final PathAttributes attributes = new IRODSAttributesFinderFeature(session).find(test); assertEquals(content.length, attributes.getSize()); final InputStream in = session.getFeature(Read.class).read(test, new TransferStatus(), new DisabledConnectionCallback()); final byte[] buffer = new byte[content.length]; IOUtils.readFully(in, buffer); in.close(); assertArrayEquals(content, buffer); } { final byte[] newcontent = new RandomStringGenerator.Builder().build().generate(10).getBytes(); final TransferStatus status = new TransferStatus(); status.setAppend(false); status.setLength(newcontent.length); assertTrue(new IRODSWriteFeature(session).append(test, status.getLength(), PathCache.empty()).append); assertEquals(content.length, new IRODSWriteFeature(session).append(test, status.getLength(), PathCache.empty()).size, 0L); final StatusOutputStream<Integer> out = new IRODSWriteFeature(session).write(test, status, new DisabledConnectionCallback()); assertNotNull(out); assertNotNull(out.getStatus()); new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(newcontent), out); assertTrue(session.getFeature(Find.class).find(test)); final PathAttributes attributes = new IRODSAttributesFinderFeature(session).find(test); assertEquals(newcontent.length, attributes.getSize()); final InputStream in = session.getFeature(Read.class).read(test, new TransferStatus(), new DisabledConnectionCallback()); final byte[] buffer = new byte[newcontent.length]; IOUtils.readFully(in, buffer); in.close(); assertArrayEquals(newcontent, buffer); } session.getFeature(Delete.class).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback()); assertFalse(session.getFeature(Find.class).find(test)); session.close(); }
@Override public FileDescriptorOutputStream write(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { try { final IRODSFileSystemAO fs = session.getClient(); final IRODSFileOutputStream out = fs.getIRODSFileFactory().instanceIRODSFileOutputStream( file.getAbsolute(), status.isAppend() ? DataObjInp.OpenFlags.READ_WRITE : DataObjInp.OpenFlags.WRITE_TRUNCATE); return new FileDescriptorOutputStream(new PackingIrodsOutputStream(out), out.getFileDescriptor()); } catch(JargonRuntimeException e) { if(e.getCause() instanceof JargonException) { throw (JargonException) e.getCause(); } throw new DefaultExceptionMappingService().map(e); } } catch(JargonException e) { throw new IRODSExceptionMappingService().map("Uploading {0} failed", e, file); } }
IRODSWriteFeature extends AppendWriteFeature<Integer> { @Override public FileDescriptorOutputStream write(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { try { final IRODSFileSystemAO fs = session.getClient(); final IRODSFileOutputStream out = fs.getIRODSFileFactory().instanceIRODSFileOutputStream( file.getAbsolute(), status.isAppend() ? DataObjInp.OpenFlags.READ_WRITE : DataObjInp.OpenFlags.WRITE_TRUNCATE); return new FileDescriptorOutputStream(new PackingIrodsOutputStream(out), out.getFileDescriptor()); } catch(JargonRuntimeException e) { if(e.getCause() instanceof JargonException) { throw (JargonException) e.getCause(); } throw new DefaultExceptionMappingService().map(e); } } catch(JargonException e) { throw new IRODSExceptionMappingService().map("Uploading {0} failed", e, file); } } }
IRODSWriteFeature extends AppendWriteFeature<Integer> { @Override public FileDescriptorOutputStream write(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { try { final IRODSFileSystemAO fs = session.getClient(); final IRODSFileOutputStream out = fs.getIRODSFileFactory().instanceIRODSFileOutputStream( file.getAbsolute(), status.isAppend() ? DataObjInp.OpenFlags.READ_WRITE : DataObjInp.OpenFlags.WRITE_TRUNCATE); return new FileDescriptorOutputStream(new PackingIrodsOutputStream(out), out.getFileDescriptor()); } catch(JargonRuntimeException e) { if(e.getCause() instanceof JargonException) { throw (JargonException) e.getCause(); } throw new DefaultExceptionMappingService().map(e); } } catch(JargonException e) { throw new IRODSExceptionMappingService().map("Uploading {0} failed", e, file); } } IRODSWriteFeature(IRODSSession session); }
IRODSWriteFeature extends AppendWriteFeature<Integer> { @Override public FileDescriptorOutputStream write(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { try { final IRODSFileSystemAO fs = session.getClient(); final IRODSFileOutputStream out = fs.getIRODSFileFactory().instanceIRODSFileOutputStream( file.getAbsolute(), status.isAppend() ? DataObjInp.OpenFlags.READ_WRITE : DataObjInp.OpenFlags.WRITE_TRUNCATE); return new FileDescriptorOutputStream(new PackingIrodsOutputStream(out), out.getFileDescriptor()); } catch(JargonRuntimeException e) { if(e.getCause() instanceof JargonException) { throw (JargonException) e.getCause(); } throw new DefaultExceptionMappingService().map(e); } } catch(JargonException e) { throw new IRODSExceptionMappingService().map("Uploading {0} failed", e, file); } } IRODSWriteFeature(IRODSSession session); @Override FileDescriptorOutputStream write(final Path file, final TransferStatus status, final ConnectionCallback callback); @Override boolean temporary(); @Override boolean random(); }
IRODSWriteFeature extends AppendWriteFeature<Integer> { @Override public FileDescriptorOutputStream write(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { try { final IRODSFileSystemAO fs = session.getClient(); final IRODSFileOutputStream out = fs.getIRODSFileFactory().instanceIRODSFileOutputStream( file.getAbsolute(), status.isAppend() ? DataObjInp.OpenFlags.READ_WRITE : DataObjInp.OpenFlags.WRITE_TRUNCATE); return new FileDescriptorOutputStream(new PackingIrodsOutputStream(out), out.getFileDescriptor()); } catch(JargonRuntimeException e) { if(e.getCause() instanceof JargonException) { throw (JargonException) e.getCause(); } throw new DefaultExceptionMappingService().map(e); } } catch(JargonException e) { throw new IRODSExceptionMappingService().map("Uploading {0} failed", e, file); } } IRODSWriteFeature(IRODSSession session); @Override FileDescriptorOutputStream write(final Path file, final TransferStatus status, final ConnectionCallback callback); @Override boolean temporary(); @Override boolean random();  }