Skip to content

Commit

Permalink
Bug579081 optimization convert schema base64 to byte array (#1448)
Browse files Browse the repository at this point in the history
Signed-off-by: lananda <lalitha.ananda@oracle.com>
  • Loading branch information
lananda committed Mar 9, 2022
1 parent 326e4a2 commit da512f0
Showing 1 changed file with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
// Oracle - initial API and implementation from Oracle TopLink
package org.eclipse.persistence.internal.oxm;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Time;
Expand Down Expand Up @@ -1589,17 +1591,29 @@ public byte[] convertSchemaBase64ToByteArray(Object sourceObject) throws Convers
if (sourceObject instanceof String) {
//the base64 string may have contained embedded whitespaces. Try again after
//Removing any whitespaces.
StringTokenizer tokenizer = new StringTokenizer((String)sourceObject);
StringBuilder builder = new StringBuilder();
while(tokenizer.hasMoreTokens()) {
builder.append(tokenizer.nextToken());
}
byte[] bytes = Base64.base64Decode(builder.toString().getBytes());
return bytes;
return Base64.base64Decode(base64RemoveWhiteSpaces((String) sourceObject));
}
return convertObjectToByteArray(sourceObject);
}

private byte[] base64RemoveWhiteSpaces(String sourceObject) {
StringTokenizer tokenizer = new StringTokenizer(sourceObject);
ByteArrayOutputStream baos = new ByteArrayOutputStream(sourceObject.length());
try {
while (tokenizer.hasMoreTokens()) {
baos.write(tokenizer.nextToken().getBytes());
}
} catch (IOException e) {
throw ConversionException.couldNotBeConverted(sourceObject, CoreClassConstants.APBYTE, e);
} finally {
try {
baos.close();
} catch (Exception e) {
}
}
return baos.toByteArray();
}

@Override
public Object convertSchemaBase64ListToByteArrayList(Object sourceObject, CoreContainerPolicy containerPolicy, CoreAbstractSession session) throws ConversionException {
if (sourceObject instanceof String) {
Expand Down

0 comments on commit da512f0

Please sign in to comment.