CrackMe.apk
Download file
package org.apache.commons.io.output;
import java.io.IOException;
import java.io.OutputStream;
import java.io.Writer;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CoderResult;
import java.nio.charset.CodingErrorAction;
public class WriterOutputStream extends OutputStream {
private static final int DEFAULT_BUFFER_SIZE = 1024;
private final CharsetDecoder decoder;
private final ByteBuffer decoderIn;
private final CharBuffer decoderOut;
private final boolean writeImmediately;
private final Writer writer;
public WriterOutputStream(Writer writer2, CharsetDecoder charsetDecoder) {
this(writer2, charsetDecoder, 1024, false);
}
public WriterOutputStream(Writer writer2, CharsetDecoder charsetDecoder, int i, boolean z) {
this.decoderIn = ByteBuffer.allocate(128);
checkIbmJdkWithBrokenUTF16(charsetDecoder.charset());
this.writer = writer2;
this.decoder = charsetDecoder;
this.writeImmediately = z;
this.decoderOut = CharBuffer.allocate(i);
}
public WriterOutputStream(Writer writer2, Charset charset, int i, boolean z) {
this(writer2, charset.newDecoder().onMalformedInput(CodingErrorAction.REPLACE).onUnmappableCharacter(CodingErrorAction.REPLACE).replaceWith("?"), i, z);
}
public WriterOutputStream(Writer writer2, Charset charset) {
this(writer2, charset, 1024, false);
}
public WriterOutputStream(Writer writer2, String str, int i, boolean z) {
this(writer2, Charset.forName(str), i, z);
}
public WriterOutputStream(Writer writer2, String str) {
this(writer2, str, 1024, false);
}
@Deprecated
public WriterOutputStream(Writer writer2) {
this(writer2, Charset.defaultCharset(), 1024, false);
}
public void write(byte[] bArr, int i, int i2) throws IOException {
while (i2 > 0) {
int min = Math.min(i2, this.decoderIn.remaining());
this.decoderIn.put(bArr, i, min);
processInput(false);
i2 -= min;
i += min;
}
if (this.writeImmediately) {
flushOutput();
}
}
public void write(byte[] bArr) throws IOException {
write(bArr, 0, bArr.length);
}
public void write(int i) throws IOException {
write(new byte[]{(byte) i}, 0, 1);
}
public void flush() throws IOException {
flushOutput();
this.writer.flush();
}
public void close() throws IOException {
processInput(true);
flushOutput();
this.writer.close();
}
private void processInput(boolean z) throws IOException {
CoderResult decode;
this.decoderIn.flip();
while (true) {
decode = this.decoder.decode(this.decoderIn, this.decoderOut, z);
if (!decode.isOverflow()) {
break;
}
flushOutput();
}
if (decode.isUnderflow()) {
this.decoderIn.compact();
return;
}
throw new IOException("Unexpected coder result");
}
private void flushOutput() throws IOException {
if (this.decoderOut.position() > 0) {
this.writer.write(this.decoderOut.array(), 0, this.decoderOut.position());
this.decoderOut.rewind();
}
}
private static void checkIbmJdkWithBrokenUTF16(Charset charset) {
if ("UTF-16".equals(charset.name())) {
byte[] bytes = "vés".getBytes(charset);
CharsetDecoder newDecoder = charset.newDecoder();
ByteBuffer allocate = ByteBuffer.allocate(16);
CharBuffer allocate2 = CharBuffer.allocate(3);
int length = bytes.length;
int i = 0;
while (i < length) {
allocate.put(bytes[i]);
allocate.flip();
try {
newDecoder.decode(allocate, allocate2, i == length + -1);
allocate.compact();
i++;
} catch (IllegalArgumentException unused) {
throw new UnsupportedOperationException("UTF-16 requested when runninng on an IBM JDK with broken UTF-16 support. Please find a JDK that supports UTF-16 if you intend to use UF-16 with WriterOutputStream");
}
}
allocate2.rewind();
if (!"vés".equals(allocate2.toString())) {
throw new UnsupportedOperationException("UTF-16 requested when runninng on an IBM JDK with broken UTF-16 support. Please find a JDK that supports UTF-16 if you intend to use UF-16 with WriterOutputStream");
}
}
}
}
Download file