/** * Creates a new instance of {@link SwiftMockOutputStream}. * * @param account simulated Swift account * @param containerName container name * @param objectName name of file or folder to write * @param tmpDirs a list of temporary directories */ public SwiftMockOutputStream(Account account, String containerName, String objectName, List<String> tmpDirs) throws IOException { try { mAccount = account; mContainerName = containerName; mObjectName = objectName; mFile = new File(PathUtils.concatPath(CommonUtils.getTmpDir(tmpDirs), UUID.randomUUID())); mOutputStream = new BufferedOutputStream(new FileOutputStream(mFile)); } catch (Exception e) { LOG.error(e.getMessage()); throw new IOException(e); } }
/** * Creates a new temp file to write to. */ private void initNewFile() throws IOException { mFile = new File(PathUtils.concatPath(CommonUtils.getTmpDir(mTmpDirs), UUID.randomUUID())); if (mHash != null) { mLocalOutputStream = new BufferedOutputStream(new DigestOutputStream(new FileOutputStream(mFile), mHash)); } else { mLocalOutputStream = new BufferedOutputStream(new FileOutputStream(mFile)); } mPartitionOffset = 0; LOG.debug("Init new temp file @ {}", mFile.getPath()); }
/** * Creates a name instance of {@link KodoOutputStream}. * * @param key the key of the file * @param kodoClient the client for Kodo * @param tmpDirs a list of temporary directories */ public KodoOutputStream(String key, KodoClient kodoClient, List<String> tmpDirs) throws IOException { mKey = key; mKodoClient = kodoClient; mFile = new File(PathUtils.concatPath(CommonUtils.getTmpDir(tmpDirs), UUID.randomUUID())); try { mHash = MessageDigest.getInstance("MD5"); mLocalOutputStream = new BufferedOutputStream(new DigestOutputStream(new FileOutputStream(mFile), mHash)); } catch (NoSuchAlgorithmException e) { LOG.warn("Algorithm not available for MD5 hash.", e); mHash = null; mLocalOutputStream = new BufferedOutputStream(new FileOutputStream(mFile)); } }
/** * Constructs a new stream for writing a file. * * @param bucketName the name of the bucket * @param key the key of the file * @param manager the transfer manager to upload the file with * @param tmpDirs a list of temporary directories * @param sseEnabled whether or not server side encryption is enabled */ public S3AOutputStream(String bucketName, String key, TransferManager manager, List<String> tmpDirs, boolean sseEnabled) throws IOException { Preconditions.checkArgument(bucketName != null && !bucketName.isEmpty(), "Bucket name must " + "not be null or empty."); mBucketName = bucketName; mKey = key; mManager = manager; mSseEnabled = sseEnabled; mFile = new File(PathUtils.concatPath(CommonUtils.getTmpDir(tmpDirs), UUID.randomUUID())); try { mHash = MessageDigest.getInstance("MD5"); mLocalOutputStream = new BufferedOutputStream(new DigestOutputStream(new FileOutputStream(mFile), mHash)); } catch (NoSuchAlgorithmException e) { LOG.warn("Algorithm not available for MD5 hash.", e); mHash = null; mLocalOutputStream = new BufferedOutputStream(new FileOutputStream(mFile)); } }
/** * Constructs a new stream for writing a file. * * @param bucketName the name of the bucket * @param key the key of the file * @param client the JetS3t client * @param tmpDirs a list of temporary directories */ public GCSOutputStream(String bucketName, String key, GoogleStorageService client, List<String> tmpDirs) throws IOException { Preconditions.checkArgument(bucketName != null && !bucketName.isEmpty(), "Bucket name must " + "not be null or empty."); mBucketName = bucketName; mKey = key; mClient = client; mFile = new File(PathUtils.concatPath(CommonUtils.getTmpDir(tmpDirs), UUID.randomUUID())); try { mHash = MessageDigest.getInstance("MD5"); mLocalOutputStream = new BufferedOutputStream(new DigestOutputStream(new FileOutputStream(mFile), mHash)); } catch (NoSuchAlgorithmException e) { LOG.warn("Algorithm not available for MD5 hash.", e); mHash = null; mLocalOutputStream = new BufferedOutputStream(new FileOutputStream(mFile)); } }
/** * Creates a name instance of {@link COSOutputStream}. * * @param bucketName the name of the bucket * @param key the key of the file * @param client the client for COS * @param tmpDirs a list of possible temporary directories */ public COSOutputStream(String bucketName, String key, COSClient client, List<String> tmpDirs) throws IOException { Preconditions.checkArgument(bucketName != null && !bucketName.isEmpty(), "Bucket name must not be null or empty."); Preconditions.checkArgument(key != null && !key.isEmpty(), "COS path must not be null or empty."); Preconditions.checkArgument(client != null, "COSClient must not be null."); mBucketName = bucketName; mKey = key; mCosClient = client; mFile = new File(PathUtils.concatPath(CommonUtils.getTmpDir(tmpDirs), UUID.randomUUID())); try { mHash = MessageDigest.getInstance("MD5"); mLocalOutputStream = new BufferedOutputStream(new DigestOutputStream(new FileOutputStream(mFile), mHash)); } catch (NoSuchAlgorithmException e) { LOG.warn("Algorithm not available for MD5 hash.", e); mHash = null; mLocalOutputStream = new BufferedOutputStream(new FileOutputStream(mFile)); } }
/** * Creates a name instance of {@link OSSOutputStream}. * * @param bucketName the name of the bucket * @param key the key of the file * @param client the client for OSS * @param tmpDirs a list of temporary directories */ public OSSOutputStream(String bucketName, String key, OSSClient client, List<String> tmpDirs) throws IOException { Preconditions.checkArgument(bucketName != null && !bucketName.isEmpty(), "Bucket name must not be null or empty."); Preconditions.checkArgument(key != null && !key.isEmpty(), "OSS path must not be null or empty."); Preconditions.checkArgument(client != null, "OSSClient must not be null."); mBucketName = bucketName; mKey = key; mOssClient = client; mFile = new File(PathUtils.concatPath(CommonUtils.getTmpDir(tmpDirs), UUID.randomUUID())); try { mHash = MessageDigest.getInstance("MD5"); mLocalOutputStream = new BufferedOutputStream(new DigestOutputStream(new FileOutputStream(mFile), mHash)); } catch (NoSuchAlgorithmException e) { LOG.warn("Algorithm not available for MD5 hash.", e); mHash = null; mLocalOutputStream = new BufferedOutputStream(new FileOutputStream(mFile)); } }
@Test public void getTmpDir() { // Test single tmp dir String singleDir = "/tmp"; List<String> singleDirList = Arrays.asList("/tmp"); assertEquals(singleDir, CommonUtils.getTmpDir(singleDirList)); // Test multiple tmp dir List<String> multiDirs = Arrays.asList("/tmp1", "/tmp2", "/tmp3"); Set<String> results = new HashSet<>(); for (int i = 0; i < 100 || results.size() != multiDirs.size(); i++) { results.add(CommonUtils.getTmpDir(multiDirs)); } assertEquals(new HashSet<>(multiDirs), results); }
/** * Creates a new instance of {@link SwiftMockOutputStream}. * * @param account simulated Swift account * @param containerName container name * @param objectName name of file or folder to write */ public SwiftMockOutputStream(Account account, String containerName, String objectName) throws IOException { try { mAccount = account; mContainerName = containerName; mObjectName = objectName; mFile = new File(PathUtils.concatPath(CommonUtils.getTmpDir(), UUID.randomUUID())); mOutputStream = new BufferedOutputStream(new FileOutputStream(mFile)); } catch (Exception e) { LOG.error(e.getMessage()); throw new IOException(e); } }
/** * Constructs a new stream for writing a file. * * @param bucketName the name of the bucket * @param key the key of the file * @param client the JetS3t client */ public GCSOutputStream(String bucketName, String key, GoogleStorageService client) throws IOException { Preconditions.checkArgument(bucketName != null && !bucketName.isEmpty(), "Bucket name must " + "not be null or empty."); mBucketName = bucketName; mKey = key; mClient = client; mFile = new File(PathUtils.concatPath(CommonUtils.getTmpDir(), UUID.randomUUID())); try { mHash = MessageDigest.getInstance("MD5"); mLocalOutputStream = new BufferedOutputStream(new DigestOutputStream(new FileOutputStream(mFile), mHash)); } catch (NoSuchAlgorithmException e) { LOG.warn("Algorithm not available for MD5 hash.", e); mHash = null; mLocalOutputStream = new BufferedOutputStream(new FileOutputStream(mFile)); } }