org.apache.batik.util.Base64DecodeStream Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com.liferay.portal.security.antisamy
Show all versions of com.liferay.portal.security.antisamy
Liferay Portal Security AntiSamy
/*
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.batik.util;
import java.io.IOException;
import java.io.InputStream;
/**
* This class implements a Base64 Character decoder as specified in RFC1113.
* Unlike some other encoding schemes there is nothing in this encoding that
* tells the decoder where a buffer starts or stops, so to use it you will need
* to isolate your encoded data into a single chunk and then feed them
* this decoder. The simplest way to do that is to read all of the encoded
* data into a string and then use:
*
* byte data[];
* InputStream is = new ByteArrayInputStream(data);
* is = new Base64DecodeStream(is);
*
*
* On errors, this class throws a IOException with the following detail
* strings:
*
* "Base64DecodeStream: Bad Padding byte (2)."
* "Base64DecodeStream: Bad Padding byte (1)."
*
*
* @author Thomas DeWeese
* @author Vincent Hardy
* @author Chuck McManis
* @version $Id: Base64DecodeStream.java 1831630 2018-05-15 12:56:55Z ssteiner $
*/
public class Base64DecodeStream extends InputStream {
InputStream src;
public Base64DecodeStream(InputStream src) {
this.src = src;
}
private static final byte[] pem_array = new byte[256];
static {
for (int i=0; i>>4));
out_buffer[1] = (byte)((b<<4) | (c>>>2));
out_buffer[2] = (byte)((c<<6) | d );
if (decode_buffer[3] != '=') {
// All three bytes are good.
out_offset=0;
} else if (decode_buffer[2] == '=') {
// Only one byte of output.
out_buffer[2] = out_buffer[0];
out_offset = 2;
EOF=true;
} else {
// Only two bytes of output.
out_buffer[2] = out_buffer[1];
out_buffer[1] = out_buffer[0];
out_offset = 1;
EOF=true;
}
return false;
}
}