Subversion Repositories SmartDukaan

Rev

Rev 12702 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
12459 kshitij.so 1
/*******************************************************************************
2
 *  Copyright 2009 Amazon Services.
3
 *  Licensed under the Apache License, Version 2.0 (the "License"); 
4
 *  
5
 *  You may not use this file except in compliance with the License. 
6
 *  You may obtain a copy of the License at: http://aws.amazon.com/apache2.0
7
 *  This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
8
 *  CONDITIONS OF ANY KIND, either express or implied. See the License for the 
9
 *  specific language governing permissions and limitations under the License.
10
 * ***************************************************************************** 
11
 *
12
 *  Marketplace Web Service Java Library
13
 *  API Version: 2009-01-01
14
 *  Generated: Wed Feb 18 13:28:48 PST 2009 
15
 * 
16
 */
17
 
18
package com.amazonaws.mws.samples;
19
 
20
import java.io.ByteArrayInputStream;
21
import in.shop2020.model.v1.catalog.Amazonlisted;
22
import java.io.File;
23
import java.io.FileInputStream;
24
import java.io.FileNotFoundException;
25
import java.io.IOException;
26
import java.io.PrintWriter;
27
import java.io.StringWriter;
28
import java.math.BigDecimal;
29
import java.math.BigInteger;
30
import java.nio.channels.FileChannel;
31
import java.security.DigestInputStream;
32
import java.security.MessageDigest;
33
import java.security.NoSuchAlgorithmException;
34
import java.util.Arrays;
35
import java.util.Calendar;
36
import java.util.Date;
37
import java.util.GregorianCalendar;
38
import java.util.HashMap;
39
import java.util.Iterator;
40
import java.util.List;
41
import java.util.ArrayList;
42
import java.util.Map;
43
import java.util.Random;
44
import java.util.TimeZone;
45
 
46
import javax.xml.bind.JAXBContext;
47
import javax.xml.bind.JAXBException;
48
import javax.xml.bind.Marshaller;
49
import javax.xml.datatype.DatatypeConfigurationException;
50
import javax.xml.datatype.DatatypeConstants;
51
import javax.xml.datatype.DatatypeFactory;
52
import javax.xml.datatype.XMLGregorianCalendar;
53
import javax.xml.parsers.ParserConfigurationException;
54
 
55
import com.amazonaws.mws.*;
56
import com.amazonaws.mws.model.*;
57
import com.amazonaws.mws.samples.ProcessFeed;
58
import com.amazonaws.mws.samples.CheckFeedSubmission;
59
import com.amazonaws.mws.mock.MarketplaceWebServiceMock;
60
import org.apache.commons.codec.binary.*;
61
 
62
import in.shop2020.feeds.products.AmazonEnvelope;
63
import in.shop2020.feeds.products.BaseCurrencyCodeWithDefault;
64
import in.shop2020.feeds.products.CE;
65
import in.shop2020.feeds.products.HandheldOrPDA;
66
import in.shop2020.feeds.products.Header;
67
import in.shop2020.feeds.products.Inventory;
68
import in.shop2020.feeds.products.Listings;
69
import in.shop2020.feeds.products.OverrideCurrencyAmount;
70
import in.shop2020.feeds.products.Price;
71
import in.shop2020.feeds.products.Product;
72
import in.shop2020.feeds.products.StandardProductID;
12661 kshitij.so 73
import in.shop2020.feeds.products.Price.Sale;
12459 kshitij.so 74
import in.shop2020.model.v1.catalog.CatalogService.Client;
75
import in.shop2020.model.v1.catalog.CatalogServiceException;
76
import in.shop2020.model.v1.catalog.Item;
77
import in.shop2020.model.v1.inventory.InventoryServiceException;
78
import in.shop2020.model.v1.inventory.ItemInventory;
79
import in.shop2020.thrift.clients.CatalogClient;
80
import in.shop2020.thrift.clients.InventoryClient;
81
import in.shop2020.thrift.clients.WarehouseClient;
82
import in.shop2020.utils.GmailUtils;
83
 
84
import org.apache.thrift.TException;
85
import org.apache.thrift.transport.TTransportException;
86
import org.xml.sax.SAXException;
87
 
88
/**
89
 * 
90
 * Submit Feed Samples
91
 * 
92
 * 
93
 */
94
public class SubmitFBAPricingFeedAndFetchResults {
95
 
96
	/**
97
	 * Just add a few required parameters, and try the service Submit Feed
98
	 * functionality
99
	 * 
100
	 * @param args
101
	 *            unused
102
	 *            
103
	 */
104
	/**
105
	 * @param args
106
	 * @throws TException 
107
	 * @throws CatalogServiceException 
108
	 */
109
 
110
	static java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd-HH:mm:ss");
111
	static Calendar cal=GregorianCalendar.getInstance();
112
	final public static String AMAZON_FBA_PRICING_XML   = "/home/amazon/Fbapricing"+sdf.format(cal.getTime())+".xml";
113
	final public static boolean PURGE_OR_REPLACE   = false;
114
	static long milliseconds;
115
	public static  List<Amazonlisted> aItems=null;
116
	public static List<Long> itemIdsToUpdate=null;
117
 
118
	static{
119
 
120
		CatalogClient catalogServiceClient = null;
121
		try {
122
			catalogServiceClient = new CatalogClient();
123
		} catch (TTransportException e) {
124
			// TODO Auto-generated catch block
125
			e.printStackTrace();
126
		}
127
		Client catalogClient = catalogServiceClient.getClient();
128
		try {
129
			Calendar cal=GregorianCalendar.getInstance();
130
			milliseconds = cal.getTimeInMillis();
131
			aItems = catalogClient.getAllFbaListedItems();
132
 
133
		} catch (TException e) {
134
			// TODO Auto-generated catch block
135
			e.printStackTrace();
136
		}
137
 
138
	}
139
	public static void main(String... args) throws CatalogServiceException, TException {
140
 
141
		/**************************************************	**********************
142
		 * Access Key ID and Secret Access Key ID, obtained from:
143
		 * http://aws.amazon.com
144
		 ***********************************************************************/
145
 
146
 
147
		//public static final String marketplaceId = "A21TJRUUN4KGV";
148
 
149
 
150
 
151
 
152
		final String accessKeyId = "AKIAII3SGRXBJDPCHSGQ";
153
		final String secretAccessKey = "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";
154
 
155
		final String appName = "Test";
156
		final String appVersion = "1.0";
157
 
158
		MarketplaceWebServiceConfig config = new MarketplaceWebServiceConfig();
159
 
160
		/************************************************************************
161
		 * Uncomment to set the appropriate MWS endpoint.
162
		 ************************************************************************/
163
		// US
164
		// config.setServiceURL("https://mws.amazonservices.com");
165
		// UK
166
		// config.setServiceURL("https://mws.amazonservices.co.uk");
167
		// Germany
168
		// config.setServiceURL("https://mws.amazonservices.de");
169
		// France
170
		// config.setServiceURL("https://mws.amazonservices.fr");
171
		// Italy
172
		// config.setServiceURL("https://mws.amazonservices.it");
173
		// Japan
174
		// config.setServiceURL("https://mws.amazonservices.jp");
175
		// China
176
		// config.setServiceURL("https://mws.amazonservices.com.cn");
177
		// Canada
178
		// config.setServiceURL("https://mws.amazonservices.ca");
179
		// India
180
		config.setServiceURL("https://mws.amazonservices.in");
181
 
182
 
183
		/************************************************************************
184
		 * You can also try advanced configuration options. Available options are:
185
		 *
186
		 *  - Signature Version
187
		 *  - Proxy Host and Proxy Port
188
		 *  - User Agent String to be sent to Marketplace Web Service
189
		 *
190
		 ***********************************************************************/
191
 
192
		/************************************************************************
193
		 * Instantiate Http Client Implementation of Marketplace Web Service        
194
		 ***********************************************************************/
195
 
196
		MarketplaceWebService service = new MarketplaceWebServiceClient(
197
				accessKeyId, secretAccessKey, appName, appVersion, config);
198
 
199
 
200
		/************************************************************************
201
		 * Setup request parameters and uncomment invoke to try out sample for
202
		 * Submit Feed
203
		 ***********************************************************************/
204
 
205
		/************************************************************************
206
		 * Marketplace and Merchant IDs are required parameters for all
207
		 * Marketplace Web Service calls.
208
		 ***********************************************************************/
209
		//final String merchantId = "AF6E300VE0X4D";
210
		final String merchantId = "AF6E3O0VE0X4D";	
211
		// marketplaces to which this feed will be submitted; look at the
212
		// API reference document on the MWS website to see which marketplaces are
213
		// included if you do not specify the list yourself
214
		final IdList marketplaces = new IdList(Arrays.asList("A21TJRUUN4KGV"));
215
 
216
		SubmitFeedRequest requestpricing = new SubmitFeedRequest();
217
		requestpricing.setMerchant(merchantId);
218
		requestpricing.setMarketplaceIdList(marketplaces);
219
		requestpricing.setFeedType("_POST_PRODUCT_PRICING_DATA_");
220
		// MWS exclusively offers a streaming interface for uploading your
221
		// feeds. This is because
222
		// feed sizes can grow to the 1GB+ range - and as your business grows
223
		// you could otherwise
224
		// silently reach the feed size where your in-memory solution will no
225
		// longer work, leaving you
226
		// puzzled as to why a solution that worked for a long time suddenly
227
		// stopped working though
228
		// you made no changes. For the same reason, we strongly encourage you
229
		// to generate your feeds to
230
		// local disk then upload them directly from disk to MWS via Java -
231
		// without buffering them in JavaFileNotFoundException
232
		// memory in their entirety.
233
		// Note: MarketplaceWebServiceClient will not retry a submit feed request
234
		// because there is no way to reset the InputStream from our client. 
235
		// To enable retry, recreate the InputStream and resubmit the feed
236
		// with the new InputStream. 
237
		//
238
		try {
239
			createFBAPricingFeed();
240
			FileInputStream pricingfis = new FileInputStream(AMAZON_FBA_PRICING_XML);
241
			requestpricing.setContentMD5(computeContentMD5HeaderValue(pricingfis));
242
			requestpricing.setFeedContent(pricingfis);
243
		} catch (FileNotFoundException e) {
244
			// TODO Auto-generated catch block
245
			e.printStackTrace();
246
		}
247
 
248
		try {
249
			invokeSubmitFeed(service,requestpricing);
250
			Thread.sleep(180);
251
		} catch (InterruptedException e) {
252
			// TODO Auto-generated catch block
253
			e.printStackTrace();
254
		}
255
 
256
	}
257
 
258
	/**
259
	 * Submit Feed request sample Uploads a file for processing together with
260
	 * the necessary metadata to process the file, such as which type of feed it
261
	 * is. PurgeAndReplace if true means that your existing e.g. inventory is
262
	 * wiped out and replace with the contents ocf this feed - use with caution
263
	 * (the default is false).
264
	 * 
265
	 * @param service
266
	 *            instance of MarketplaceWebService service
267
	 * @param request
268
	 *            Action to invoke
269
	 * @throws InterruptedException 
270
	 */
271
	public static void invokeSubmitFeed(MarketplaceWebService service,
272
			SubmitFeedRequest request) throws InterruptedException {
273
		boolean retry = false;
274
		int retryCount = 0;
275
		while (!retry) {
276
			try {
277
 
278
				SubmitFeedResponse response = service.submitFeed(request);
279
 
280
				System.out.println("SubmitFeed Action Response");
281
				System.out
282
				.println("=============================================================================");
283
				System.out.println();
284
 
285
				System.out.print("    SubmitFeedResponse");
286
				System.out.println();
287
				FeedSubmissionInfo feedSubmissionInfo=null;
288
				if (response.isSetSubmitFeedResult()) {
289
					System.out.print("        SubmitFeedResult");
290
					System.out.println();
291
					SubmitFeedResult submitFeedResult = response
292
					.getSubmitFeedResult();
293
					if (submitFeedResult.isSetFeedSubmissionInfo()) {
294
						System.out.print("            FeedSubmissionInfo");
295
						System.out.println();
296
						feedSubmissionInfo = submitFeedResult
297
						.getFeedSubmissionInfo();
298
						if (feedSubmissionInfo.isSetFeedSubmissionId()) {
299
							System.out.print("                FeedSubmissionId");
300
							System.out.println();
301
							System.out.print("                    "
302
									+ feedSubmissionInfo.getFeedSubmissionId());
303
 
304
							System.out.println();
305
						}
306
						if (feedSubmissionInfo.isSetFeedType()) {
307
							System.out.print("                FeedType");
308
							System.out.println();
309
							System.out.print("                    "
310
									+ feedSubmissionInfo.getFeedType());
311
							System.out.println();
312
						}
313
						if (feedSubmissionInfo.isSetSubmittedDate()) {
314
							System.out.print("                SubmittedDate");
315
							System.out.println();
316
							System.out.print("                    "
317
									+ feedSubmissionInfo.getSubmittedDate());
318
							System.out.println();
319
						}
320
						if (feedSubmissionInfo.isSetFeedProcessingStatus()) {
321
							System.out
322
							.print("                FeedProcessingStatus");
323
							System.out.println();
324
							System.out.print("                    "
325
									+ feedSubmissionInfo.getFeedProcessingStatus());
326
							System.out.println();
327
						}
328
						if (feedSubmissionInfo.isSetStartedProcessingDate()) {
329
							System.out
330
							.print("                StartedProcessingDate");
331
							System.out.println();
332
							System.out
333
							.print("                    "
334
									+ feedSubmissionInfo
335
									.getStartedProcessingDate());
336
							System.out.println();
337
						}
338
						if (feedSubmissionInfo.isSetCompletedProcessingDate()) {
339
							System.out
340
							.print("                CompletedProcessingDate");
341
							System.out.println();
342
							System.out.print("                    "
343
									+ feedSubmissionInfo
344
									.getCompletedProcessingDate());
345
							System.out.println();
346
						}
347
					}
348
				}
349
				if (response.isSetResponseMetadata()) {
350
					System.out.print("        ResponseMetadata");
351
					System.out.println();
352
					ResponseMetadata responseMetadata = response
353
					.getResponseMetadata();
354
					if (responseMetadata.isSetRequestId()) {
355
						System.out.print("            RequestId");
356
						System.out.println();
357
						System.out.print("                "
358
								+ responseMetadata.getRequestId());
359
						System.out.println();
360
					}
361
				}
362
				System.out.println(response.getResponseHeaderMetadata());
363
				retry =true;
12702 kshitij.so 364
				System.out.println("============Sleeping For 5 Minutes=============");
365
				Thread.sleep(300000);
12459 kshitij.so 366
				CheckFeedSubmission checkResult = new CheckFeedSubmission();
367
				ProcessFeed feedProcessingResult=null;
368
				int checkResultCount=0;
369
				try {
370
					while (feedProcessingResult == null){
371
						feedProcessingResult = checkResult.getResult(feedSubmissionInfo.getFeedSubmissionId(),"FullFbaPricing",milliseconds,itemIdsToUpdate);
372
						if (feedProcessingResult == null){
373
							checkResultCount++;
12702 kshitij.so 374
							if (checkResultCount == 2){
12459 kshitij.so 375
								String text = "";
376
								String[] sendTo = { "eng@shop2020.in" };
377
								String emailSubjectTxt = "Unable To Receive FBA Pricing Feed Result.Submission Id "+feedSubmissionInfo.getFeedSubmissionId();
378
								String emailFromAddress = "build@shop2020.in";
379
								String password = "cafe@nes";
380
								GmailUtils mailer = new GmailUtils();
381
								try {
382
									mailer.sendSSLMessage(sendTo, emailSubjectTxt, text, emailFromAddress, password, new ArrayList<File>());
383
								}
384
								catch (Exception e) {
385
									e.printStackTrace();
386
								}
387
								System.exit(1);
388
							}
389
							System.out.println("=====Feed Result Not Ready Retry Again After 5 Minutes=============");
390
							Thread.sleep(300000);
391
 
392
						}
393
 
394
					}
395
 
396
				} catch (ParserConfigurationException e) {
397
					// TODO Auto-generated catch block
398
					e.printStackTrace();
399
				} catch (SAXException e) {
400
					// TODO Auto-generated catch block
401
					e.printStackTrace();
402
				} catch (IOException e) {
403
					// TODO Auto-generated catch block
404
					e.printStackTrace();
405
				}
406
				String emailSubjectTxt="";
407
				String[] sendTo;
408
				if (Boolean.valueOf(feedProcessingResult.getResult())){
409
					emailSubjectTxt = "FBA Pricing Feed Success "+sdf.format(cal.getTime());
12969 amit.gupta 410
					sendTo = new String[]{  "kshitij.sood@shop2020.in"};
12459 kshitij.so 411
				}
412
				else {
413
					emailSubjectTxt = "FBA Pricing Feed Failure "+sdf.format(cal.getTime());
414
					sendTo = new String[]{ "eng@shop2020.in"};
415
				}
416
				String text = "MessagesProcessed "+feedProcessingResult.getProcessed()+"\n"+"MessagesSuccessful "+feedProcessingResult.getSuccess()+"\n"+"" +
417
				"MessagesWithError "+feedProcessingResult.getError()+"\n"+"MessagesWithWarning "+feedProcessingResult.getWarn(); 
418
				String emailFromAddress = "build@shop2020.in";
419
				String password = "cafe@nes";
420
				GmailUtils mailer = new GmailUtils();
421
				try {
422
					mailer.sendSSLMessage(sendTo, emailSubjectTxt, text, emailFromAddress, password, "/home/amazon/feedSubmission"+"FullFbaPricing"+"Result.xml");
423
				}
424
				catch (Exception ex) {
425
					ex.printStackTrace();
426
				}
427
				System.out.println();
428
			} catch (MarketplaceWebServiceException ex) {
429
 
430
				System.out.println("Caught Exception: " + ex.getMessage());
431
				System.out.println("Response Status Code: " + ex.getStatusCode());
432
				System.out.println("Error Code: " + ex.getErrorCode());
433
				System.out.println("Error Type: " + ex.getErrorType());
434
				System.out.println("Request ID: " + ex.getRequestId());
435
				System.out.print("XML: " + ex.getXML());
436
				System.out.println("ResponseHeaderMetadata: " + ex.getResponseHeaderMetadata());
437
 
438
				if (retryCount == 2) {
439
					StringWriter errors = new StringWriter();
440
					ex.printStackTrace(new PrintWriter(errors));
441
					String text = errors.toString(); 
442
					String[] sendTo = { "eng@shop2020.in" };
443
					String emailSubjectTxt = "Unable To Send FBA Pricing Feed ";
444
					String emailFromAddress = "build@shop2020.in";
445
					String password = "cafe@nes";
446
					GmailUtils mailer = new GmailUtils();
447
					try {
448
						mailer.sendSSLMessage(sendTo, emailSubjectTxt, text, emailFromAddress, password, new ArrayList<File>());
449
					}
450
					catch (Exception e) {
451
						e.printStackTrace();
452
					}
453
					System.exit(1);
454
				}
455
				retryCount++;
456
				Thread.sleep(60000);
457
			}
458
		}
459
	}
460
 
12661 kshitij.so 461
	public static long getTimeInMilliseconds(){
462
        Calendar cal=GregorianCalendar.getInstance();
463
        return Long.valueOf(cal.getTimeInMillis());
464
    }
12459 kshitij.so 465
 
466
	public static void createFBAPricingFeed() throws CatalogServiceException, TException{
467
 
468
 
469
		File file = new File(AMAZON_FBA_PRICING_XML);
470
		AmazonEnvelope amazonenvelope =  new AmazonEnvelope();
471
		Header header = new Header();
472
		header.setDocumentVersion("1.0");
473
		header.setMerchantIdentifier("AF6E3O0VE0X4D");
474
		header.setOverrideReleaseId(null);
475
		amazonenvelope.setHeader(header);
476
		amazonenvelope.setMessageType("Price");
477
		amazonenvelope.setMarketplaceName(null);
478
		amazonenvelope.setPurgeAndReplace(PURGE_OR_REPLACE);
479
		JAXBContext context;
480
		Marshaller m=null;
481
		try {
482
			context = JAXBContext.newInstance(AmazonEnvelope.class);
483
			m = context.createMarshaller();
484
		} catch (JAXBException e1) {
485
			e1.printStackTrace();
486
		}
487
		XMLGregorianCalendar today = null;
488
		Calendar localCalendar = Calendar.getInstance(TimeZone.getDefault());
489
 
490
		int currentMonth = localCalendar.get(Calendar.MONTH);
491
		int currentYear = localCalendar.get(Calendar.YEAR);
492
		int currentDayOfMonth = localCalendar.get(Calendar.DAY_OF_MONTH);
493
 
494
 
495
		try {
496
			today = DatatypeFactory.newInstance()
497
			.newXMLGregorianCalendar(
498
					new GregorianCalendar(currentYear,currentMonth,currentDayOfMonth));
499
			System.out.println(today);
500
		} catch (DatatypeConfigurationException e) {
501
			// TODO Auto-generated catch block
502
			e.printStackTrace(); 
503
		}
504
		amazonenvelope.setEffectiveDate(today);
505
		List <AmazonEnvelope.Message> messages = amazonenvelope.getMessage();
506
		int count=0;
507
		System.out.println("Inside price listing creation");
508
		itemIdsToUpdate = new ArrayList<Long>();
509
		for(Amazonlisted AItem:aItems){
510
			if(!AItem.isSuppressFbaPriceUpdate()){
511
				AmazonEnvelope.Message message = new AmazonEnvelope.Message();
512
				Price price = new Price();
513
				price.setSKU("FBA"+String.valueOf(AItem.getItemid()));
514
				OverrideCurrencyAmount overridecurrencyamount = new OverrideCurrencyAmount();
515
				overridecurrencyamount.setCurrency(BaseCurrencyCodeWithDefault.DEFAULT);
516
				overridecurrencyamount.setValue(BigDecimal.valueOf(AItem.getFbaPrice()));
517
				price.setStandardPrice(overridecurrencyamount);
518
				Random rand = new Random();
519
				message.setMessageID(BigInteger.valueOf(Math.abs(rand.nextInt())));
12702 kshitij.so 520
				if ((AItem.getFbaPromoStartDate()<=getTimeInMilliseconds() && AItem.getFbaPromoEndDate()>=getTimeInMilliseconds()) && !AItem.isIsFbaPromotionActive()){
521
				    //safety check
522
				    continue;
523
				}
12661 kshitij.so 524
				if (AItem.isIsFbaPromotionActive() && (AItem.getFbaPromoStartDate()<=getTimeInMilliseconds() && AItem.getFbaPromoEndDate()>=getTimeInMilliseconds())){
525
                    Sale sale = new Sale();
526
                    OverrideCurrencyAmount overridesaleamount = new OverrideCurrencyAmount();
527
                    overridesaleamount.setCurrency(BaseCurrencyCodeWithDefault.DEFAULT);
528
                    overridesaleamount.setValue(BigDecimal.valueOf(AItem.getFbaPromoPrice()));
529
                    sale.setSalePrice(overridesaleamount);
530
                    XMLGregorianCalendar startDate = null;
531
                    XMLGregorianCalendar endDate = null;
532
                    try {
533
                        GregorianCalendar calendar = new GregorianCalendar();
534
                        calendar.setTimeInMillis(AItem.getFbaPromoStartDate());
535
                        startDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(
536
                                calendar);
537
                        calendar.setTimeInMillis(AItem.getFbaPromoEndDate());
538
                        endDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(
539
                                calendar);
540
                    } catch (DatatypeConfigurationException e) {
541
                        e.printStackTrace();
542
                        continue;
543
                    }
544
                    sale.setStartDate(startDate);
545
                    sale.setEndDate(endDate);
546
                    price.setSale(sale);
547
                }
12459 kshitij.so 548
				message.setPrice(price);
549
				message.setOperationType("Update");
550
				messages.add(message);
551
				itemIdsToUpdate.add(AItem.getItemid());
552
				count++;
553
			}
554
		}
555
		try {
556
			m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
557
			m.marshal(amazonenvelope, file);
558
			m.marshal(amazonenvelope, System.out);
559
 
560
		} catch (Exception e) {
561
			// TODO Auto-generated catch block
562
			e.printStackTrace();
563
		}
564
 
565
 
566
	}
567
 
568
 
569
	public static String computeContentMD5HeaderValue( FileInputStream fis) {
570
		try {
571
			DigestInputStream dis = new DigestInputStream( fis,
572
					MessageDigest.getInstance( "MD5" ));
573
			byte[] buffer = new byte[8192];
574
			while( dis.read( buffer ) > 0 );
575
			String md5Content = new String(Base64.encodeBase64(dis.getMessageDigest().digest())
576
			);
577
			// Effectively resets the stream to be beginning of the file via a
578
			fis.getChannel().position( 0 );
579
			return md5Content;
580
		} catch (NoSuchAlgorithmException e) {
581
			// TODO Auto-generated catch block
582
			e.printStackTrace();
583
		} catch (IOException e) {
584
			// TODO Auto-generated catch block
585
			e.printStackTrace();
586
		}
587
		return null;
588
 
589
	}
590
 
591
 
592
 
593
 
594
 
595
}