public URL uploadStream(ActiveMQBlobMessage message, InputStream in) throws JMSException, IOException { File f = getFile(message); try(FileOutputStream out = new FileOutputStream(f)) { byte[] buffer = new byte[policy.getBufferSize()]; for (int c = in.read(buffer); c != -1; c = in.read(buffer)) { out.write(buffer, 0, c); out.flush(); } } // File.toURL() is deprecated return f.toURI().toURL(); }
public FTPStrategy(BlobTransferPolicy transferPolicy) throws MalformedURLException { this.transferPolicy = transferPolicy; this.url = new URL(this.transferPolicy.getUploadUrl()); }
protected BlobTransferPolicy createBlobTransferPolicy() { return new BlobTransferPolicy(); }
public String getUploadUrl() { if (uploadUrl == null) { uploadUrl = getBrokerUploadUrl(); if (uploadUrl == null) { uploadUrl = getDefaultUploadUrl(); } } return uploadUrl; }
public BlobUploader(BlobTransferPolicy blobTransferPolicy, InputStream in) { // need to do a defensive copy this.blobTransferPolicy = blobTransferPolicy.copy(); this.in = in; }
public BlobUploadStrategy getUploadStrategy() { if (uploadStrategy == null) { uploadStrategy = createUploadStrategy(); } return uploadStrategy; }
public BlobDownloadStrategy getDownloadStrategy() { if(downloadStrategy == null) { downloadStrategy = createDownloadStrategy(); } return downloadStrategy; }
public BlobDownloadStrategy getStrategy() { return getBlobTransferPolicy().getDownloadStrategy(); } }
public BlobUploadStrategy getStrategy() { return getBlobTransferPolicy().getUploadStrategy(); } }
public String getUploadUrl() { if (uploadUrl == null) { uploadUrl = getBrokerUploadUrl(); if (uploadUrl == null) { uploadUrl = getDefaultUploadUrl(); } } return uploadUrl; }
public BlobUploader(BlobTransferPolicy blobTransferPolicy, File file) { // need to do a defensive copy this.blobTransferPolicy = blobTransferPolicy.copy(); this.file = file; }
public BlobUploadStrategy getUploadStrategy() { if (uploadStrategy == null) { uploadStrategy = createUploadStrategy(); } return uploadStrategy; }
public BlobDownloadStrategy getDownloadStrategy() { if(downloadStrategy == null) { downloadStrategy = createDownloadStrategy(); } return downloadStrategy; }
public BlobDownloadStrategy getStrategy() { return getBlobTransferPolicy().getDownloadStrategy(); } }
public BlobUploadStrategy getStrategy() { return getBlobTransferPolicy().getUploadStrategy(); } }
/** * Create the root folder if not exist * * @throws MalformedURLException * @throws URISyntaxException */ protected void createRootFolder() throws MalformedURLException, URISyntaxException { rootFile = new File(new URL(policy.getUploadUrl()).toURI()); if (rootFile.exists() == false) { rootFile.mkdirs(); } else if (rootFile.isDirectory() == false) { throw new IllegalArgumentException("Given url is not a directory " + rootFile ); } } /*
public String getUploadUrl() { if (uploadUrl == null) { uploadUrl = getBrokerUploadUrl(); if (uploadUrl == null) { uploadUrl = getDefaultUploadUrl(); } } return uploadUrl; }
public URL uploadStream(ActiveMQBlobMessage message, InputStream fis) throws JMSException, IOException { URL url = createMessageURL(message); HttpURLConnection connection = (HttpURLConnection)url.openConnection(); connection.setRequestMethod("PUT"); connection.setDoOutput(true); // use chunked mode or otherwise URLConnection loads everything into // memory // (chunked mode not supported before JRE 1.5) connection.setChunkedStreamingMode(transferPolicy.getBufferSize()); try(OutputStream os = connection.getOutputStream()) { byte[] buf = new byte[transferPolicy.getBufferSize()]; for (int c = fis.read(buf); c != -1; c = fis.read(buf)) { os.write(buf, 0, c); os.flush(); } } catch (IOException error) { throw new IOException("PUT failed to: " + url, error); } if (!isSuccessfulCode(connection.getResponseCode())) { throw new IOException("PUT to " + url + " was not successful: " + connection.getResponseCode() + " " + connection.getResponseMessage()); } return url; }
public BlobDownloader(BlobTransferPolicy transferPolicy) { // need to do a defensive copy this.blobTransferPolicy = transferPolicy.copy(); }
/** * Returns a copy of this policy object */ public BlobTransferPolicy copy() { BlobTransferPolicy that = new BlobTransferPolicy(); that.defaultUploadUrl = this.defaultUploadUrl; that.brokerUploadUrl = this.brokerUploadUrl; that.uploadUrl = this.uploadUrl; that.bufferSize = this.bufferSize; that.uploadStrategy = this.uploadStrategy; that.downloadStrategy = this.downloadStrategy; return that; }