@Test public void testWriteThreaded() 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 session1 = new IRODSSession(host); session1.open(Proxy.DIRECT, new DisabledHostKeyCallback(), new DisabledLoginCallback()); session1.login(Proxy.DIRECT, new DisabledLoginCallback(), new DisabledCancelCallback()); final IRODSSession session2 = new IRODSSession(host); session2.open(Proxy.DIRECT, new DisabledHostKeyCallback(), new DisabledLoginCallback()); session2.login(Proxy.DIRECT, new DisabledLoginCallback(), new DisabledCancelCallback()); final CountDownLatch cw1 = new CountDownLatch(1); final CountDownLatch cw2 = new CountDownLatch(1); final Path test1 = new Path(new IRODSHomeFinderService(session1).find(), UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); final Path test2 = new Path(new IRODSHomeFinderService(session2).find(), UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); final byte[] content = RandomUtils.nextBytes(68400); final OutputStream out1 = new IRODSWriteFeature(session1).write(test1, new TransferStatus().append(false).length(content.length), new DisabledConnectionCallback()); final OutputStream out2 = new IRODSWriteFeature(session2).write(test2, new TransferStatus().append(false).length(content.length), new DisabledConnectionCallback()); new Thread(new Runnable() { @Override public void run() { try { new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), out2); } catch(BackgroundException e) { fail(); } finally { cw1.countDown(); } } }).start(); new Thread(new Runnable() { @Override public void run() { try { new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), out1); } catch(BackgroundException e) { fail(); } finally { cw2.countDown(); } } }).start(); cw1.await(); cw2.await(); final CountDownLatch cr1 = new CountDownLatch(1); final CountDownLatch cr2 = new CountDownLatch(1); new Thread(new Runnable() { @Override public void run() { try { final InputStream in1 = session1.getFeature(Read.class).read(test1, new TransferStatus(), new DisabledConnectionCallback()); final byte[] buffer1 = new byte[content.length]; IOUtils.readFully(in1, buffer1); in1.close(); assertArrayEquals(content, buffer1); } catch(Exception e) { fail(); } finally { cr1.countDown(); } } }).start(); new Thread(new Runnable() { @Override public void run() { try { final InputStream in2 = session2.getFeature(Read.class).read(test2, new TransferStatus(), new DisabledConnectionCallback()); final byte[] buffer2 = new byte[content.length]; IOUtils.readFully(in2, buffer2); in2.close(); assertArrayEquals(content, buffer2); } catch(Exception e) { fail(); } finally { cr2.countDown(); } } }).start(); cr1.await(); cr2.await(); session1.close(); session2.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();  }