Created
May 23, 2012 06:30
-
-
Save md-5/2773549 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.raphfrk.craftproxylitest; | |
import java.io.FilterInputStream; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import org.bouncycastle.crypto.StreamCipher; | |
public class CiphIn extends FilterInputStream { | |
private StreamCipher ciph; | |
private byte[] c; | |
private byte[] d; | |
private int e; | |
private int f; | |
private boolean g; | |
public CiphIn(InputStream in, StreamCipher ciph) { | |
super(in); | |
this.ciph = ciph; | |
this.c = new byte[2048]; | |
this.d = new byte[2048]; | |
} | |
private int a() throws IOException { | |
int i = super.available(); | |
if (i <= 0) { | |
i = 1; | |
} | |
if (i > this.d.length) { | |
i = super.read(this.d, 0, this.d.length); | |
} else { | |
i = super.read(this.d, 0, i); | |
} | |
if (i < 0) { | |
if (this.g) { | |
return -1; | |
} | |
try { | |
this.f = 0; | |
} catch (Exception localException1) { | |
throw new IOException("error processing stream: " + localException1.toString()); | |
} | |
this.e = 0; | |
this.g = true; | |
if (this.e == this.f) { | |
return -1; | |
} | |
} else { | |
this.e = 0; | |
try { | |
this.ciph.processBytes(d, 0, i, c, 0); | |
this.f = i; | |
} catch (Exception localException2) { | |
throw new IOException("error processing stream: " + localException2.toString()); | |
} | |
if (this.f == 0) { | |
return a(); | |
} | |
} | |
return this.f; | |
} | |
@Override | |
public int read() throws IOException { | |
if ((this.e == this.f) && (a() < 0)) { | |
return -1; | |
} | |
return this.c[(this.e++)] & 0xFF; | |
} | |
@Override | |
public int read(byte[] paramArrayOfByte) throws IOException { | |
return read(paramArrayOfByte, 0, paramArrayOfByte.length); | |
} | |
@Override | |
public int read(byte[] paramArrayOfByte, int paramInt1, int paramInt2) throws IOException { | |
if ((this.e == this.f) && (a() < 0)) { | |
return -1; | |
} | |
int i = this.f - this.e; | |
if (paramInt2 > i) { | |
System.arraycopy(this.c, this.e, paramArrayOfByte, paramInt1, i); | |
this.e = this.f; | |
return i; | |
} | |
System.arraycopy(this.c, this.e, paramArrayOfByte, paramInt1, paramInt2); | |
this.e += paramInt2; | |
return paramInt2; | |
} | |
@Override | |
public long skip(long paramLong) { | |
if (paramLong <= 0L) { | |
return 0L; | |
} | |
int i = this.f - this.e; | |
if (paramLong > i) { | |
this.e = this.f; | |
return i; | |
} | |
this.e += (int) paramLong; | |
return (int) paramLong; | |
} | |
@Override | |
public int available() { | |
return this.f - this.e; | |
} | |
@Override | |
public boolean markSupported() { | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment