-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added a debug probe for diagnosing "Not in GZIP format" problem.
See http://www.nabble.com/Archiving-Site%3A-IOException%3A-Not-in-GZIP-format-td20325401.html git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@13009 71c3de6d-444a-0410-be80-ed276b4c234a
- Loading branch information
kohsuke
committed
Nov 5, 2008
1 parent
3ed4f3a
commit 694ed60
Showing
2 changed files
with
81 additions
and
2 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package hudson.util; | ||
|
||
import org.apache.commons.io.output.ByteArrayOutputStream; | ||
|
||
import java.io.FilterInputStream; | ||
import java.io.InputStream; | ||
import java.io.IOException; | ||
|
||
/** | ||
* {@link FilterInputStream} that buffers the first N bytes to a byte array on the side. | ||
* This byte array can be then accessed later. | ||
* | ||
* <p> | ||
* Useful for sniffing the content of the stream after the error is discovered. | ||
* | ||
* @author Kohsuke Kawaguchi | ||
*/ | ||
public class HeadBufferingStream extends FilterInputStream { | ||
private final ByteArrayOutputStream side; | ||
private final int sideBufferSize; | ||
|
||
public HeadBufferingStream(InputStream in, int sideBufferSize) { | ||
super(in); | ||
this.sideBufferSize = sideBufferSize; | ||
this.side = new ByteArrayOutputStream(sideBufferSize); | ||
} | ||
|
||
public int read() throws IOException { | ||
int i = in.read(); | ||
if(i>=0 && space()>0) | ||
side.write(i); | ||
return i; | ||
} | ||
|
||
public int read(byte b[], int off, int len) throws IOException { | ||
int r = in.read(b, off, len); | ||
if(r>0) { | ||
int sp = space(); | ||
if(sp>0) | ||
side.write(b,off,Math.min(r, sp)); | ||
} | ||
return r; | ||
} | ||
|
||
/** | ||
* Available space in the {@link #side} buffer. | ||
*/ | ||
private int space() { | ||
return sideBufferSize-side.size(); | ||
} | ||
|
||
/** | ||
* Read until we fill up the side buffer. | ||
*/ | ||
public void fillSide() throws IOException { | ||
byte[] buf = new byte[space()]; | ||
while(space()>0) { | ||
if(read(buf)<0) | ||
return; | ||
} | ||
} | ||
|
||
/** | ||
* Gets the side buffer content. | ||
*/ | ||
public byte[] getSideBuffer() { | ||
return side.toByteArray(); | ||
} | ||
} |