01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.aegis.services.base64;
19:
20: import java.util.zip.CRC32;
21:
22: import org.apache.commons.logging.Log;
23: import org.apache.commons.logging.LogFactory;
24:
25: public class BinaryDataService {
26: private final Log log = LogFactory.getLog(getClass());
27:
28: public String verifyDataIntegrity(byte[] data, int length,
29: long crc32) {
30: log.debug("verifyDataIntegrity([" + data.length
31: + " bytes of data], " + length + ", " + crc32
32: + ") called.");
33:
34: String status = getStatusForData(data, length, crc32);
35:
36: log.debug("verifyDataIntegrity status: " + status);
37: return status;
38: }
39:
40: /**
41: * @param data
42: * @param length
43: * @param crc32
44: * @return
45: */
46: private String getStatusForData(byte[] data, int length, long crc32) {
47:
48: String status;
49: if (data.length != length) {
50: status = "data.length == " + data.length + ", should be "
51: + length;
52: } else {
53: CRC32 computedCrc32 = new CRC32();
54: computedCrc32.update(data);
55: if (computedCrc32.getValue() != crc32) {
56: status = "Computed crc32 == "
57: + computedCrc32.getValue() + ", should be "
58: + crc32;
59: } else {
60: status = "OK";
61: }
62: }
63: return status;
64: }
65:
66: }
|