Move SerialUtil.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/a88c7162 Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/a88c7162 Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/a88c7162 Branch: refs/heads/master Commit: a88c7162d70dcc02df686750022c9ea5474c9391 Parents: fc6b63c Author: Matt Sicker <[email protected]> Authored: Sat Feb 27 20:11:33 2016 -0600 Committer: Matt Sicker <[email protected]> Committed: Sat Feb 27 20:11:33 2016 -0600 ---------------------------------------------------------------------- .../java/org/apache/log4j/util/SerialUtil.java | 65 -------------------- .../apache/logging/log4j/junit/SerialUtil.java | 65 ++++++++++++++++++++ .../log4j/message/ObjectMessageTest.java | 2 +- 3 files changed, 66 insertions(+), 66 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a88c7162/log4j-api/src/test/java/org/apache/log4j/util/SerialUtil.java ---------------------------------------------------------------------- diff --git a/log4j-api/src/test/java/org/apache/log4j/util/SerialUtil.java b/log4j-api/src/test/java/org/apache/log4j/util/SerialUtil.java deleted file mode 100644 index 9a58941..0000000 --- a/log4j-api/src/test/java/org/apache/log4j/util/SerialUtil.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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 org.apache.log4j.util; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; - -/** - * Utility class to facilitate serializing and deserializing objects. - */ -public class SerialUtil { - private SerialUtil() { - } - - /** - * Serializes the specified object and returns the result as a byte array. - * @param obj the object to serialize - * @return the serialized object - */ - public static byte[] serialize(final Serializable obj) { - try { - final ByteArrayOutputStream bas = new ByteArrayOutputStream(8192); - final ObjectOutputStream oos = new ObjectOutputStream(bas); - oos.writeObject(obj); - oos.flush(); - return bas.toByteArray(); - } catch (final Exception ex) { - throw new IllegalStateException("Could not serialize", ex); - } - } - - /** - * Deserialize an object from the specified byte array and returns the result. - * @param data byte array representing the serialized object - * @return the deserialized object - */ - @SuppressWarnings("unchecked") - public static <T> T deserialize(final byte[] data) { - try { - final ByteArrayInputStream bas = new ByteArrayInputStream(data); - final ObjectInputStream ois = new ObjectInputStream(bas); - return (T) ois.readObject(); - } catch (final Exception ex) { - throw new IllegalStateException("Could not deserialize", ex); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a88c7162/log4j-api/src/test/java/org/apache/logging/log4j/junit/SerialUtil.java ---------------------------------------------------------------------- diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/junit/SerialUtil.java b/log4j-api/src/test/java/org/apache/logging/log4j/junit/SerialUtil.java new file mode 100644 index 0000000..211eca6 --- /dev/null +++ b/log4j-api/src/test/java/org/apache/logging/log4j/junit/SerialUtil.java @@ -0,0 +1,65 @@ +/* + * 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 org.apache.logging.log4j.junit; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; + +/** + * Utility class to facilitate serializing and deserializing objects. + */ +public class SerialUtil { + private SerialUtil() { + } + + /** + * Serializes the specified object and returns the result as a byte array. + * @param obj the object to serialize + * @return the serialized object + */ + public static byte[] serialize(final Serializable obj) { + try { + final ByteArrayOutputStream bas = new ByteArrayOutputStream(8192); + final ObjectOutputStream oos = new ObjectOutputStream(bas); + oos.writeObject(obj); + oos.flush(); + return bas.toByteArray(); + } catch (final Exception ex) { + throw new IllegalStateException("Could not serialize", ex); + } + } + + /** + * Deserialize an object from the specified byte array and returns the result. + * @param data byte array representing the serialized object + * @return the deserialized object + */ + @SuppressWarnings("unchecked") + public static <T> T deserialize(final byte[] data) { + try { + final ByteArrayInputStream bas = new ByteArrayInputStream(data); + final ObjectInputStream ois = new ObjectInputStream(bas); + return (T) ois.readObject(); + } catch (final Exception ex) { + throw new IllegalStateException("Could not deserialize", ex); + } + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a88c7162/log4j-api/src/test/java/org/apache/logging/log4j/message/ObjectMessageTest.java ---------------------------------------------------------------------- diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/message/ObjectMessageTest.java b/log4j-api/src/test/java/org/apache/logging/log4j/message/ObjectMessageTest.java index e0a4c49..189feb7 100644 --- a/log4j-api/src/test/java/org/apache/logging/log4j/message/ObjectMessageTest.java +++ b/log4j-api/src/test/java/org/apache/logging/log4j/message/ObjectMessageTest.java @@ -19,7 +19,7 @@ package org.apache.logging.log4j.message; import java.io.Serializable; import java.math.BigDecimal; -import org.apache.log4j.util.SerialUtil; +import org.apache.logging.log4j.junit.SerialUtil; import org.junit.Test; import static org.junit.Assert.*;
