Subversion Repositories SmartDukaan

Rev

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