Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void callingMethod(){
- // Upload using BulkAPI
- // Call the createJob()
- // You send data in batches in separate HTTP POST requests.
- JobInfo job = createJob(bConnection);
- // Create a Batch with Binary Attachments
- if (job != null) {
- System.out.println("Job is created.");
- List<BatchInfo> batchInfoList = new ArrayList<BatchInfo>();
- try {
- List<BatchInfo> batchInfos = new ArrayList<BatchInfo>();
- // Make the upload using BulkAPI
- createBatch(menifestFile, batchInfos, bConnection, job, attachments);
- batchInfoList.addAll(batchInfos);
- } catch (AsyncApiException ex){}
- if (batchInfoList.size() > 0) {
- closeJob(bConnection, job.getId());
- awaitCompletion(bConnection, job, batchInfoList);
- checkResults(bConnection, job, batchInfoList, emailInformation, acceptedList);
- }
- } // END if (job != null)
- }
- // Main Method used for Binary Attachments using Bulk API
- /**
- * @param menifestFile
- * The information held in XML / CSV format about the Name, Body and ParentId of the different files used. It requires us to place the information using relative path of Files.
- * @param batchInfos
- * The BatchInfo class used for storing the errors, recordId
- * @param connection
- * The BulkConnection used for createing batches. Here, a special method named createBatchWithInputStreamAttachments(JobInfo job, InputStream menifestFile, Map<String, InputStream> attachments) is used
- * @param jobInfo
- * The JobInfo reference used already used for creation of Job and to be used in referencing a Batch with the created Job's id
- * @param attachments
- * Map<String, InputStream> -> Key - The FileName must be matched with the Name of Menifest File
- * Value - The actual path-> absolute path of the File
- * @throws IOException
- * @throws AsyncApiException
- */
- private static void createBatch(FileInputStream menifestFile,
- List<BatchInfo> batchInfos, BulkConnection connection, JobInfo jobInfo, Map<String, InputStream> attachments)
- throws IOException, AsyncApiException{
- // Dummy Data {{{{{// Map<String, InputStream> att = new HashMap<String, InputStream>();
- // att.put("2014-04-18_231314.png", new FileInputStream("C:\\Users\\user\\Desktop\\upload\\2014-04-18_231314.png"));
- // att.put("request_copy.txt", new FileInputStream("C:\\Users\\user\\Desktop\\upload\\request_copy.txt"));}}}}}
- BatchInfo batchInfo = connection.createBatchWithInputStreamAttachments(jobInfo,
- //new FileInputStream("C:\\Users\\user\\Desktop\\upload\\request.txt"),
- menifestFile,
- //att
- attachments);
- batchInfos.add(batchInfo);
- } // END private static void createBatch(File tmpFiel, List<BatchInfo> batchInfos, BulkConnection connection, JobInfo jobInfo)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement