-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
195 additions
and
0 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
src/main/java/com/alibaba/com/caucho/hessian/io/BitSetHandle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright (c) 2001-2008 Caucho Technology, Inc. All rights reserved. | ||
* | ||
* The Apache Software License, Version 1.1 | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in | ||
* the documentation and/or other materials provided with the | ||
* distribution. | ||
* | ||
* 3. The end-user documentation included with the redistribution, if | ||
* any, must include the following acknowlegement: | ||
* "This product includes software developed by the | ||
* Caucho Technology (http://www.caucho.com/)." | ||
* Alternately, this acknowlegement may appear in the software itself, | ||
* if and wherever such third-party acknowlegements normally appear. | ||
* | ||
* 4. The names "Hessian", "Resin", and "Caucho" must not be used to | ||
* endorse or promote products derived from this software without prior | ||
* written permission. For written permission, please contact | ||
* info@caucho.com. | ||
* | ||
* 5. Products derived from this software may not be called "Resin" | ||
* nor may "Resin" appear in their names without prior written | ||
* permission of Caucho Technology. | ||
* | ||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | ||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS | ||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, | ||
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT | ||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR | ||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE | ||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN | ||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* @author Scott Ferguson | ||
*/ | ||
|
||
package com.alibaba.com.caucho.hessian.io; | ||
|
||
import java.util.BitSet; | ||
|
||
/** | ||
* Handle for a BitSet object. | ||
*/ | ||
public class BitSetHandle implements java.io.Serializable, HessianHandle { | ||
private long[] words; | ||
|
||
public BitSetHandle(long[] words) { | ||
this.words = words; | ||
} | ||
|
||
private Object readResolve() { | ||
if (words == null) { | ||
return null; | ||
} | ||
|
||
return BitSet.valueOf(words); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
src/main/java/com/alibaba/com/caucho/hessian/io/BitSetSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved. | ||
* | ||
* The Apache Software License, Version 1.1 | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in | ||
* the documentation and/or other materials provided with the | ||
* distribution. | ||
* | ||
* 3. The end-user documentation included with the redistribution, if | ||
* any, must include the following acknowlegement: | ||
* "This product includes software developed by the | ||
* Caucho Technology (http://www.caucho.com/)." | ||
* Alternately, this acknowlegement may appear in the software itself, | ||
* if and wherever such third-party acknowlegements normally appear. | ||
* | ||
* 4. The names "Hessian", "Resin", and "Caucho" must not be used to | ||
* endorse or promote products derived from this software without prior | ||
* written permission. For written permission, please contact | ||
* info@caucho.com. | ||
* | ||
* 5. Products derived from this software may not be called "Resin" | ||
* nor may "Resin" appear in their names without prior written | ||
* permission of Caucho Technology. | ||
* | ||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | ||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS | ||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, | ||
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT | ||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR | ||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE | ||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN | ||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* @author Scott Ferguson | ||
*/ | ||
|
||
package com.alibaba.com.caucho.hessian.io; | ||
|
||
import java.io.IOException; | ||
import java.util.BitSet; | ||
|
||
/** | ||
* Serializing a BitSet. | ||
*/ | ||
public class BitSetSerializer extends AbstractSerializer { | ||
private static BitSetSerializer SERIALIZER = new BitSetSerializer(); | ||
|
||
public static BitSetSerializer create() { | ||
return SERIALIZER; | ||
} | ||
|
||
@Override | ||
public void writeObject(Object obj, AbstractHessianOutput out) | ||
throws IOException { | ||
if (obj == null) | ||
out.writeNull(); | ||
else { | ||
BitSet bitSet = (BitSet) obj; | ||
|
||
out.writeObject(new BitSetHandle(bitSet.toLongArray())); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/test/java/com/alibaba/com/caucho/hessian/io/BitSetSerializerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.alibaba.com.caucho.hessian.io; | ||
|
||
import java.io.IOException; | ||
import java.util.BitSet; | ||
import java.util.Locale; | ||
|
||
import org.junit.Test; | ||
|
||
import com.alibaba.com.caucho.hessian.io.base.SerializeTestBase; | ||
|
||
import junit.framework.TestCase; | ||
|
||
public class BitSetSerializerTest extends SerializeTestBase { | ||
|
||
/** {@linkplain BitSetSerializer#writeObject(Object, AbstractHessianOutput)} */ | ||
@Test | ||
public void bitSet() throws IOException { | ||
long[] words = new long[3]; | ||
words[0] = 0x0102030405060708L; | ||
words[1] = 0x1112131415161718L; | ||
words[2] = 0x2122232425262728L; | ||
assertBitSet(null); | ||
assertBitSet(new BitSet()); | ||
assertBitSet(new BitSet(1)); | ||
assertBitSet(BitSet.valueOf(words)); | ||
} | ||
|
||
private void assertBitSet(BitSet bitSet) throws IOException { | ||
TestCase.assertEquals(bitSet, baseHessian2Serialize(bitSet)); | ||
TestCase.assertEquals(bitSet, baseHessianSerialize(bitSet)); | ||
} | ||
} |