Tuesday, August 25, 2015

Java service to calculate CRC32 checksum for byte array

Input: stringInput
Ouput: checksumValue

import com.wm.data.*;
import com.wm.util.Values;
import com.wm.app.b2b.server.Service;
import com.wm.app.b2b.server.ServiceException;
import java.util.zip.CRC32;
import java.util.zip.Checksum;

public final class CRC32_SVC

{

/**
* The primary method for the Java service
*
* @param pipeline
*            The IData pipeline
* @throws ServiceException
*/
public static final void CRC32(IData pipeline) throws ServiceException {

// pipeline
IDataCursor pipelineCursor = pipeline.getCursor();
String stringInput = IDataUtil.getString( pipelineCursor, "stringInput" );
pipelineCursor.destroy();

byte bytes[] = stringInput.getBytes();
Checksum checksum = new CRC32();
checksum.update(bytes, 0, bytes.length);
long checksumValue = checksum.getValue();

// pipeline
IDataCursor pipelineCursor_1 = pipeline.getCursor();
IDataUtil.put( pipelineCursor_1, "checksumValue", checksumValue );
pipelineCursor_1.destroy();

}

// --- <<IS-BEGIN-SHARED-SOURCE-AREA>> ---



// --- <<IS-END-SHARED-SOURCE-AREA>> ---
}

Results:
stringInput: mahesh
checksumValue: 1443886754

2 comments:


  1. #CloudGen is a proud Platinum Sponsor for #DigitalBusinessDays 2016 - Join us on 3-4 Oct,16 at The W NewYork
    https://www.linkedin.com/groups/2090488/2090488-6173917281454678018

    ReplyDelete
    Replies
    1. @ CloudGensys,
      Thanks for sharing your ad in regards to #DigitalBusinessDays 2016 however this blog is not meant for posting ads like this. Hope you understand it...

      If you have any comments on the blog content kindly mention and do not pasted ads on this site. You can use other social networking sites.

      Delete