Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | 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 in.shop2020.logistics.LogisticsInfo;
23
import in.shop2020.logistics.DeliveryType;
24
import in.shop2020.logistics.LogisticsServiceException;
25
 
26
import java.io.File;
27
import java.io.FileInputStream;
28
import java.io.FileNotFoundException;
29
import java.io.IOException;
30
import java.math.BigDecimal;
31
import java.math.BigInteger;
32
import java.nio.channels.FileChannel;
33
import java.security.DigestInputStream;
34
import java.security.MessageDigest;
35
import java.security.NoSuchAlgorithmException;
36
import java.util.Arrays;
37
import java.util.Calendar;
38
import java.util.Date;
39
import java.util.GregorianCalendar;
40
import java.util.HashMap;
41
import java.util.Iterator;
42
import java.util.List;
43
import java.util.ArrayList;
44
import java.util.Map;
45
import java.util.Random;
46
import java.util.TimeZone;
47
 
48
import javax.xml.bind.JAXBContext;
49
import javax.xml.bind.JAXBException;
50
import javax.xml.bind.Marshaller;
51
import javax.xml.datatype.DatatypeConfigurationException;
52
import javax.xml.datatype.DatatypeConstants;
53
import javax.xml.datatype.DatatypeFactory;
54
import javax.xml.datatype.XMLGregorianCalendar;
55
 
56
import com.amazonaws.mws.*;
57
import com.amazonaws.mws.model.*;
58
import com.amazonaws.mws.mock.MarketplaceWebServiceMock;
59
import org.apache.commons.codec.binary.*;
60
 
61
import in.shop2020.feeds.products.AmazonEnvelope;
62
import in.shop2020.feeds.products.BaseCurrencyCodeWithDefault;
63
import in.shop2020.feeds.products.CE;
64
import in.shop2020.feeds.products.HandheldOrPDA;
65
import in.shop2020.feeds.products.Header;
66
import in.shop2020.feeds.products.Inventory;
67
import in.shop2020.feeds.products.Listings;
68
import in.shop2020.feeds.products.OverrideCurrencyAmount;
69
import in.shop2020.feeds.products.Price;
70
import in.shop2020.feeds.products.Product;
71
import in.shop2020.feeds.products.StandardProductID;
72
import in.shop2020.model.v1.catalog.CatalogService.Client;
73
import in.shop2020.model.v1.catalog.CatalogServiceException;
74
import in.shop2020.model.v1.catalog.Item;
75
import in.shop2020.model.v1.catalog.status;
76
import in.shop2020.model.v1.inventory.AmazonInventorySnapshot;
77
import in.shop2020.model.v1.inventory.InventoryServiceException;
78
import in.shop2020.model.v1.inventory.ItemInventory;
79
import in.shop2020.model.v1.inventory.Warehouse;
80
import in.shop2020.model.v1.inventory.WarehouseType;
81
import in.shop2020.thrift.clients.CatalogClient;
82
import in.shop2020.thrift.clients.InventoryClient;
83
import in.shop2020.thrift.clients.LogisticsClient;
84
import org.apache.thrift.TException;
85
import org.apache.thrift.transport.TTransportException;
86
 
87
/**
88
 * 
89
 * Submit Feed Samples
90
 * 
91
 * 
92
 */
93
public class SubmitNonFBAInventoryFeed {
94
 
95
    /**
96
     * Just add a few required parameters, and try the service Submit Feed
97
     * functionality
98
     * 
99
     * @param args
100
     *            unused
101
     *            
102
     */
103
    /**
104
     * @param args
105
     * @throws TException 
106
     * @throws CatalogServiceException 
107
     */
108
 
109
	final public static String AMAZON_NON_FBA_INVENTORY_XML = "/home/vikram/Nonfbainventory.xml";
110
	final public static boolean PURGE_OR_REPLACE   = false;
111
	public static  List<Amazonlisted> amazonNonFbaListedItems=null;
112
	public static List<in.shop2020.model.v1.catalog.Item> aliveItemsMap=null;
113
	public static Map<Long,AmazonItem> allItemsAmazonMap   = new HashMap<Long,AmazonItem>();
114
 
115
	static{
116
 
117
		CatalogClient catalogServiceClient = null;
118
		Map<Long,ItemInventory> availability= new HashMap<Long,ItemInventory>();
119
		try {
120
			catalogServiceClient = new CatalogClient();
121
		} catch (TTransportException e) {
122
			// TODO Auto-generated catch block
123
			e.printStackTrace();
124
		}
125
		Client catalogClient = catalogServiceClient.getClient();
126
		try {
127
			amazonNonFbaListedItems = catalogClient.getAllNonFbaListedItems();
128
			aliveItemsMap = catalogClient.getAllAliveItems();
129
			InventoryClient inventoryServiceClient = null;
130
			try {
131
				inventoryServiceClient = new InventoryClient();
132
			} catch (TTransportException e) {
133
				// TODO Auto-generated catch block
134
				e.printStackTrace();
135
			}
136
			in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
137
			availability = inventoryClient.getInventorySnapshot(0);
138
			List<Warehouse> warehouses = inventoryClient.getWarehouses(WarehouseType.OURS_THIRDPARTY,null,0,0,0);
139
			List<Long> thirdpartywarehouseids = new ArrayList<Long>();
140
			for(Warehouse warehouse:warehouses){
141
				thirdpartywarehouseids.add(warehouse.getId());
142
			}
143
			//System.out.println("Availability is " + availability );
144
			for(in.shop2020.model.v1.catalog.Item thriftItem:aliveItemsMap){
145
				long available=0;
146
				long reserve=0;
147
				AmazonItem item;
148
				if(availability.get(thriftItem.getId())!=null){ 
149
					ItemInventory iteminventory = availability.get(thriftItem.getId());
150
					Map<Long,Long> itemavailability = new HashMap<Long,Long>();
151
					itemavailability = iteminventory.getAvailability();
152
					for (Map.Entry<Long,Long> entry : itemavailability.entrySet()) {
153
						if(!thirdpartywarehouseids.contains(entry.getKey())){
154
							available =  available + entry.getValue();	
155
						}
156
					}
157
					Map<Long,Long> itemreserve = new HashMap<Long,Long>();
158
					itemreserve = iteminventory.getReserved();
159
					for (Map.Entry<Long,Long> entry : itemreserve.entrySet()) {
160
						if(!thirdpartywarehouseids.contains(entry.getKey())){
161
							reserve =  reserve + entry.getValue();
162
						}
163
					}
164
					item= new AmazonItem(thriftItem.getId(),available,reserve,thriftItem.getHoldInventory(),thriftItem.getDefaultInventory(),thriftItem.isRisky(),thriftItem.getItemStatus());
165
				}
166
				else{
167
					item = new AmazonItem(thriftItem.getId(),0,0,thriftItem.getHoldInventory(),thriftItem.getDefaultInventory(),thriftItem.isRisky(),thriftItem.getItemStatus());
168
				}
169
 
170
				//System.out.println(" Item details are " + thriftItem.getId() +" " + available + " " + reserve + " " + thriftItem.getHoldInventory() + " "+ thriftItem.getDefaultInventory() + " " + thriftItem.isRisky());
171
				//System.out.println("+++++++++++++++++++++++");
172
				allItemsAmazonMap.put(thriftItem.getId(),item);
173
 
174
			}
175
 
176
		} catch (TException e) {
177
			// TODO Auto-generated catch block
178
			e.printStackTrace();
179
		}
180
 
181
	}
182
    public static void main(String... args) throws CatalogServiceException, TException {
183
 
184
        /**************************************************	**********************
185
         * Access Key ID and Secret Access Key ID, obtained from:
186
         * http://aws.amazon.com
187
         ***********************************************************************/
188
 
189
 
190
    	//public static final String marketplaceId = "A21TJRUUN4KGV";
191
 
192
 
193
 
194
 
195
        final String accessKeyId = "AKIAII3SGRXBJDPCHSGQ";
196
        final String secretAccessKey = "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";
197
 
198
        final String appName = "Test";
199
        final String appVersion = "1.0";
200
 
201
        MarketplaceWebServiceConfig config = new MarketplaceWebServiceConfig();
202
 
203
        /************************************************************************
204
         * Uncomment to set the appropriate MWS endpoint.
205
         ************************************************************************/
206
        // US
207
        // config.setServiceURL("https://mws.amazonservices.com");
208
        // UK
209
        // config.setServiceURL("https://mws.amazonservices.co.uk");
210
        // Germany
211
        // config.setServiceURL("https://mws.amazonservices.de");
212
        // France
213
        // config.setServiceURL("https://mws.amazonservices.fr");
214
        // Italy
215
        // config.setServiceURL("https://mws.amazonservices.it");
216
        // Japan
217
        // config.setServiceURL("https://mws.amazonservices.jp");
218
        // China
219
        // config.setServiceURL("https://mws.amazonservices.com.cn");
220
        // Canada
221
        // config.setServiceURL("https://mws.amazonservices.ca");
222
        // India
223
        config.setServiceURL("https://mws.amazonservices.in");
224
 
225
        /************************************************************************
226
         * You can also try advanced configuration options. Available options are:
227
         *
228
         *  - Signature Version
229
         *  - Proxy Host and Proxy Port
230
         *  - User Agent String to be sent to Marketplace Web Service
231
         *
232
         ***********************************************************************/
233
 
234
        /************************************************************************
235
         * Instantiate Http Client Implementation of Marketplace Web Service        
236
         ***********************************************************************/
237
 
238
        MarketplaceWebService service = new MarketplaceWebServiceClient(
239
                accessKeyId, secretAccessKey, appName, appVersion, config);
240
 
241
 
242
        /************************************************************************
243
         * Setup request parameters and uncomment invoke to try out sample for
244
         * Submit Feed
245
         ************************************
246
         ************************************/
247
 
248
        /************************************************************************
249
         * Marketplace and Merchant IDs are required parameters for all
250
         * Marketplace Web Service calls.
251
         ***********************************************************************/
252
        //final String merchantId = "AF6E300VE0X4D";
253
        final String merchantId = "AF6E3O0VE0X4D";	
254
        // marketplaces to which this feed will be submitted; look at the
255
        // API reference document on the MWS website to see which marketplaces are
256
        // included if you do not specify the list yourself
257
        final IdList marketplaces = new IdList(Arrays.asList(
258
        		"A21TJRUUN4KGV"));
259
 
260
        SubmitFeedRequest requestinventory = new SubmitFeedRequest();
261
        requestinventory.setMerchant(merchantId);
262
        requestinventory.setMarketplaceIdList(marketplaces);
263
        requestinventory.setFeedType("_POST_INVENTORY_AVAILABILITY_DATA_");
264
        // MWS exclusively offers a streaming interface for uploading your
265
        // feeds. This is because
266
        // feed sizes can grow to the 1GB+ range - and as your business grows
267
        // you could otherwise
268
        // silently reach the feed size where your in-memory solution will no
269
        // longer work, leaving you
270
        // puzzled as to why a solution that worked for a long time suddenly
271
        // stopped working though
272
        // you made no changes. For the same reason, we strongly encourage you
273
        // to generate your feeds to
274
        // local disk then upload them directly from disk to MWS via Java -
275
        // without buffering them in JavaFileNotFoundException
276
        // memory in their entirety.
277
        // Note: MarketplaceWebServiceClient will not retry a submit feed request
278
        // because there is no way to reset the InputStream from our client. 
279
        // To enable retry, recreate the InputStream and resubmit the feed
280
        // with the new InputStream. 
281
        //
282
        try {
283
 
284
        	createNonFbaInventoryFeed();
285
        	FileInputStream inventoryfis = new FileInputStream(AMAZON_NON_FBA_INVENTORY_XML);
286
        	requestinventory.setContentMD5(computeContentMD5HeaderValue(inventoryfis));
287
			requestinventory.setFeedContent(inventoryfis);
288
		} catch (FileNotFoundException e) {
289
			// TODO Auto-generated catch block
290
			e.printStackTrace();
291
		}
292
 
293
		try {
294
				invokeSubmitFeed(service,requestinventory);
295
				Thread.sleep(30);
296
			} catch (InterruptedException e) {
297
			// TODO Auto-generated catch block
298
			e.printStackTrace();
299
		}
300
 
301
    }
302
 
303
    /**
304
     * Submit Feed request sample Uploads a file for processing together with
305
     * the necessary metadata to process the file, such as which type of feed it
306
     * is. PurgeAndReplace if true means that your existing e.g. inventory is
307
     * wiped out and replace with the contents ocf this feed - use with caution
308
     * (the default is false).
309
     * 
310
     * @param service
311
     *            instance of MarketplaceWebService service
312
     * @param request
313
     *            Action to invoke
314
     */
315
    public static void invokeSubmitFeed(MarketplaceWebService service,
316
            SubmitFeedRequest request) {
317
        try {
318
 
319
            SubmitFeedResponse response = service.submitFeed(request);
320
 
321
            System.out.println("SubmitFeed Action Response");
322
            System.out
323
            .println("=============================================================================");
324
            System.out.println();
325
 
326
            System.out.print("    SubmitFeedResponse");
327
            System.out.println();
328
            if (response.isSetSubmitFeedResult()) {
329
                System.out.print("        SubmitFeedResult");
330
                System.out.println();
331
                SubmitFeedResult submitFeedResult = response
332
                .getSubmitFeedResult();
333
                if (submitFeedResult.isSetFeedSubmissionInfo()) {
334
                    System.out.print("            FeedSubmissionInfo");
335
                    System.out.println();
336
                    FeedSubmissionInfo feedSubmissionInfo = submitFeedResult
337
                    .getFeedSubmissionInfo();
338
                    if (feedSubmissionInfo.isSetFeedSubmissionId()) {
339
                        System.out.print("                FeedSubmissionId");
340
                        System.out.println();
341
                        System.out.print("                    "
342
                                + feedSubmissionInfo.getFeedSubmissionId());
343
 
344
                        System.out.println();
345
                    }
346
                    if (feedSubmissionInfo.isSetFeedType()) {
347
                        System.out.print("                FeedType");
348
                        System.out.println();
349
                        System.out.print("                    "
350
                                + feedSubmissionInfo.getFeedType());
351
                        System.out.println();
352
                    }
353
                    if (feedSubmissionInfo.isSetSubmittedDate()) {
354
                        System.out.print("                SubmittedDate");
355
                        System.out.println();
356
                        System.out.print("                    "
357
                                + feedSubmissionInfo.getSubmittedDate());
358
                        System.out.println();
359
                    }
360
                    if (feedSubmissionInfo.isSetFeedProcessingStatus()) {
361
                        System.out
362
                        .print("                FeedProcessingStatus");
363
                        System.out.println();
364
                        System.out.print("                    "
365
                                + feedSubmissionInfo.getFeedProcessingStatus());
366
                        System.out.println();
367
                    }
368
                    if (feedSubmissionInfo.isSetStartedProcessingDate()) {
369
                        System.out
370
                        .print("                StartedProcessingDate");
371
                        System.out.println();
372
                        System.out
373
                        .print("                    "
374
                                + feedSubmissionInfo
375
                                .getStartedProcessingDate());
376
                        System.out.println();
377
                    }
378
                    if (feedSubmissionInfo.isSetCompletedProcessingDate()) {
379
                        System.out
380
                        .print("                CompletedProcessingDate");
381
                        System.out.println();
382
                        System.out.print("                    "
383
                                + feedSubmissionInfo
384
                                .getCompletedProcessingDate());
385
                        System.out.println();
386
                    }
387
                }
388
            }
389
            if (response.isSetResponseMetadata()) {
390
                System.out.print("        ResponseMetadata");
391
                System.out.println();
392
                ResponseMetadata responseMetadata = response
393
                .getResponseMetadata();
394
                if (responseMetadata.isSetRequestId()) {
395
                    System.out.print("            RequestId");
396
                    System.out.println();
397
                    System.out.print("                "
398
                            + responseMetadata.getRequestId());
399
                    System.out.println();
400
                }
401
            }
402
            System.out.println(response.getResponseHeaderMetadata());
403
            System.out.println();
404
            System.out.println();
405
 
406
        } catch (MarketplaceWebServiceException ex) {
407
 
408
            System.out.println("Caught Exception: " + ex.getMessage());
409
            System.out.println("Response Status Code: " + ex.getStatusCode());
410
            System.out.println("Error Code: " + ex.getErrorCode());
411
            System.out.println("Error Type: " + ex.getErrorType());
412
            System.out.println("Request ID: " + ex.getRequestId());
413
            System.out.print("XML: " + ex.getXML());
414
            System.out.println("ResponseHeaderMetadata: " + ex.getResponseHeaderMetadata());
415
        }
416
    }
417
 
418
 
419
    public static void createNonFbaInventoryFeed() throws CatalogServiceException, TException{
420
 
421
 
422
    	File file = new File(AMAZON_NON_FBA_INVENTORY_XML);
423
    	AmazonEnvelope amazonenvelope =  new AmazonEnvelope();
424
    	Header header = new Header();
425
    	header.setDocumentVersion("1.0");
426
    	header.setMerchantIdentifier("AF6E3O0VE0X4D");
427
    	header.setOverrideReleaseId(null);
428
    	amazonenvelope.setHeader(header);
429
    	amazonenvelope.setMessageType("Inventory");
430
    	amazonenvelope.setMarketplaceName(null);
431
    	//amazonenvelope.setPurgeAndReplace(PURGE_OR_REPLACE);
432
    	amazonenvelope.setPurgeAndReplace(true);
433
    	JAXBContext context;
434
    	Marshaller m=null;
435
    	try {
436
    		context = JAXBContext.newInstance(AmazonEnvelope.class);
437
    		m = context.createMarshaller();
438
    	} catch (JAXBException e1) {
439
    		// TODO Auto-generated catch block
440
    		e1.printStackTrace();
441
    	}
442
 
443
    	XMLGregorianCalendar today = null;
444
    	XMLGregorianCalendar restockdate = null;
445
    	//Calendar localCalendar = Calendar.getInstance();
446
    	Calendar localCalendar = Calendar.getInstance(TimeZone.getDefault());
447
    	int currentMonth = localCalendar.get(Calendar.MONTH);
448
    	int currentYear = localCalendar.get(Calendar.YEAR);
449
    	int currentDayOfMonth = localCalendar.get(Calendar.DAY_OF_MONTH);
450
 
451
    	try {
452
    		today = DatatypeFactory.newInstance()
453
    		.newXMLGregorianCalendar(
454
    				new GregorianCalendar(currentYear,currentMonth,currentDayOfMonth));
455
    		restockdate = DatatypeFactory.newInstance()
456
    		.newXMLGregorianCalendar(
457
    				new GregorianCalendar(currentYear,currentMonth,currentDayOfMonth));
458
    		restockdate.setTimezone(DatatypeConstants.FIELD_UNDEFINED);
459
    		restockdate.setTime(DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED);  
460
 
461
 
462
    	} catch (DatatypeConfigurationException e) {
463
    		// TODO Auto-generated catch block
464
    		e.printStackTrace();
465
    	}
466
    	amazonenvelope.setEffectiveDate(today);
467
    	LogisticsClient logisticsServiceClient;
468
		in.shop2020.logistics.LogisticsService.Client logisticsClient=null;
469
    	try {
470
    		logisticsServiceClient = new LogisticsClient("logistics_service_prod_server_host","logistics_service_prod_server_port");
471
    		logisticsClient = logisticsServiceClient.getClient();
472
 
473
		} catch (TTransportException e) {
474
			// TODO Auto-generated catch block
475
			e.printStackTrace();
476
		}
477
 
478
    	List <AmazonEnvelope.Message> messages = amazonenvelope.getMessage();
479
    	InventoryClient inventoryServiceClient = new InventoryClient();
480
    	in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
481
    	long time = System.currentTimeMillis();
482
    	for(Amazonlisted AItem:amazonNonFbaListedItems){
483
    		if(!AItem.isIsInventoryOverride()){
484
    			AmazonEnvelope.Message message = new AmazonEnvelope.Message();	
485
    			Inventory inventory = new Inventory();
486
    			AmazonItem item = allItemsAmazonMap.get(AItem.getItemid());
487
    			if(item!=null && !item.getStatus().equals(status.PAUSED)){
488
    				long actualavailibility = (item.getAvailability() - item.getReserve());
489
    				long holdinventory = item.getHoldInventory();
490
    				long defaultinventory = item.getDefaultInventory();
491
    				if(item.getRisky()){
492
    					if(actualavailibility > holdinventory){
493
    						inventory.setQuantity(BigInteger.valueOf(actualavailibility - holdinventory));
494
    					}
495
    					else{
496
    						inventory.setQuantity(BigInteger.valueOf(0));
497
    					}
498
    				}		
499
    				else{
500
    					if(actualavailibility > defaultinventory){
501
    						inventory.setQuantity(BigInteger.valueOf(actualavailibility));
502
    					}
503
    					else{
504
    						inventory.setQuantity(BigInteger.valueOf(defaultinventory));
505
    					}
506
    				}
507
    			}
508
    			else{
509
    				inventory.setQuantity(BigInteger.valueOf(0));
510
    			}
511
    			AmazonInventorySnapshot amazonInventorySnapshot = new AmazonInventorySnapshot();
512
			    amazonInventorySnapshot.setAvailability(inventory.getQuantity().longValue());
513
        		amazonInventorySnapshot.setItem_id(AItem.getItemid());
514
    			inventoryClient.addOrUpdateAmazonInventoryForItem(amazonInventorySnapshot,time);
515
    			inventory.setSKU(Long.toString(AItem.getItemid()));
516
    			LogisticsInfo logisticinfo=new LogisticsInfo();
517
    			try {
518
				     logisticinfo = logisticsClient.getLogisticsEstimation(AItem.getItemid(),"110001",DeliveryType.COD);
519
				} catch (LogisticsServiceException e) {
520
					// TODO Auto-generated catch block
521
					e.printStackTrace();
522
				}
523
				if(AItem.isIsCustomTime()){
524
					inventory.setFulfillmentLatency(BigInteger.valueOf(AItem.getHandlingTime()));
525
				}
526
 
527
				else{
528
					inventory.setFulfillmentLatency(BigInteger.valueOf(logisticinfo.getShippingTime()));
529
				}
530
				if(inventory.getFulfillmentLatency().intValue() <= 0){
531
					inventory.setFulfillmentLatency(BigInteger.valueOf(1));
532
				}
533
    			inventory.setSwitchFulfillmentTo("MFN");
534
    			Random rand = new Random();
535
    			message.setMessageID(BigInteger.valueOf(Math.abs(rand.nextInt())));
536
    			message.setInventory(inventory);
537
    			message.setOperationType("Update");
538
    			messages.add(message);
539
    		}
540
    	}
541
    	try {
542
    		m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
543
    		m.marshal(amazonenvelope, file);
544
    		m.marshal(amazonenvelope, System.out);
545
 
546
    	} catch (Exception e) {
547
    		// TODO Auto-generated catch block
548
    		e.printStackTrace();
549
    	}
550
 
551
 
552
    }
553
 
554
 
555
 
556
    public static String computeContentMD5HeaderValue( FileInputStream fis) {
557
    	try {
558
			DigestInputStream dis = new DigestInputStream( fis,
559
					MessageDigest.getInstance( "MD5" ));
560
			byte[] buffer = new byte[8192];
561
			while( dis.read( buffer ) > 0 );
562
			String md5Content = new String(Base64.encodeBase64(dis.getMessageDigest().digest())
563
				);
564
			// Effectively resets the stream to be beginning of the file via a
565
			fis.getChannel().position( 0 );
566
			return md5Content;
567
		} catch (NoSuchAlgorithmException e) {
568
			// TODO Auto-generated catch block
569
			e.printStackTrace();
570
		} catch (IOException e) {
571
			// TODO Auto-generated catch block
572
			e.printStackTrace();
573
		}
574
		return null;
575
 
576
 }
577
 
578
 
579
 
580
 
581
 
582
}