|
| 1 | +/* |
| 2 | + * The contents of this file are subject to the terms of the Common Development and |
| 3 | + * Distribution License (the License). You may not use this file except in compliance with the |
| 4 | + * License. |
| 5 | + * |
| 6 | + * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the |
| 7 | + * specific language governing permission and limitations under the License. |
| 8 | + * |
| 9 | + * When distributing Covered Software, include this CDDL Header Notice in each file and include |
| 10 | + * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL |
| 11 | + * Header, with the fields enclosed by brackets [] replaced by your own identifying |
| 12 | + * information: "Portions copyright [year] [name of copyright owner]". |
| 13 | + * |
| 14 | + * Copyright 2023-2026 3A Systems LLC. |
| 15 | + */ |
| 16 | + |
1 | 17 | package com.iplanet.jato.util; |
2 | 18 |
|
3 | | -import java.io.ByteArrayInputStream; |
| 19 | +import com.sun.identity.shared.debug.Debug; |
| 20 | +import org.forgerock.openam.utils.IOUtils; |
| 21 | + |
4 | 22 | import java.io.ByteArrayOutputStream; |
5 | 23 | import java.io.IOException; |
6 | | -import java.io.ObjectInputStream; |
7 | 24 | import java.io.ObjectOutputStream; |
8 | 25 | import java.io.Serializable; |
9 | 26 | import java.util.Base64; |
| 27 | +import java.util.stream.Collectors; |
10 | 28 | import java.util.zip.DataFormatException; |
11 | 29 | import java.util.zip.Deflater; |
12 | 30 | import java.util.zip.DeflaterOutputStream; |
13 | 31 | import java.util.zip.Inflater; |
14 | | -import java.util.zip.InflaterInputStream; |
15 | 32 |
|
16 | 33 | public class Encoder { |
17 | 34 |
|
| 35 | + private final static Debug debug = Debug.getInstance("amConsole"); |
18 | 36 | private Encoder() { |
19 | 37 | } |
20 | 38 |
|
@@ -115,18 +133,17 @@ public static byte[] serialize(Serializable o, boolean compress) throws IOExcept |
115 | 133 | } |
116 | 134 |
|
117 | 135 | public static Object deserialize(byte[] b, boolean compressed) throws IOException, ClassNotFoundException { |
118 | | - ByteArrayInputStream bais = new ByteArrayInputStream(b); |
119 | | - InflaterInputStream iis = null; |
120 | | - ObjectInputStream ois = null; |
121 | | - if (compressed) { |
122 | | - iis = new InflaterInputStream(bais); |
123 | | - ois = new ApplicationObjectInputStream(iis); |
124 | | - } else { |
125 | | - ois = new ApplicationObjectInputStream(bais); |
| 136 | + if(debug.messageEnabled()) { |
| 137 | + String trace = StackWalker.getInstance() |
| 138 | + .walk(frames -> frames |
| 139 | + .skip(1).limit(3) |
| 140 | + .map(f -> String.format("%s.%s(%s:%d)", |
| 141 | + f.getClassName(), f.getMethodName(), |
| 142 | + f.getFileName(), f.getLineNumber())) |
| 143 | + .collect(Collectors.joining("; "))); |
| 144 | + debug.message("Encoder:deserialize callers trace: " + trace); |
126 | 145 | } |
127 | | - |
128 | | - Object result = ois.readObject(); |
129 | | - return result; |
| 146 | + return IOUtils.deserialise(b, compressed); |
130 | 147 | } |
131 | 148 | } |
132 | 149 |
|
0 commit comments