Skip to content

Commit

Permalink
Actually set new bytelists to external encoding in GzipReader.
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Jan 9, 2012
1 parent 86c50d8 commit 773a155
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/org/jruby/ext/zlib/RubyZlib.java
Original file line number Diff line number Diff line change
Expand Up @@ -1401,8 +1401,26 @@ private IRubyObject internalSepGets(ByteList sep) throws IOException {
return internalSepGets(sep, -1);
}

private ByteList newExternalByteList() {
ByteList byteList = new ByteList();
if (externalEncoding != null) byteList.setEncoding(externalEncoding);
return byteList;
}

private ByteList newExternalByteList(int size) {
ByteList byteList = new ByteList(size);
if (externalEncoding != null) byteList.setEncoding(externalEncoding);
return byteList;
}

private ByteList newExternalByteList(byte[] buffer, int start, int length, boolean copy) {
ByteList byteList = new ByteList(buffer, start, length, copy);
if (externalEncoding != null) byteList.setEncoding(externalEncoding);
return byteList;
}

private IRubyObject internalSepGets(ByteList sep, int limit) throws IOException {
ByteList result = new ByteList();
ByteList result = newExternalByteList();
if (sep.getRealSize() == 0) sep = Stream.PARAGRAPH_SEPARATOR;
int ce = -1;
// TODO: CRuby does encoding aware 'gets'. Not yet implemented.
Expand Down Expand Up @@ -1503,7 +1521,7 @@ public IRubyObject readpartial(IRubyObject[] args) {
}

private IRubyObject readPartial(int len, RubyString outbuf) throws IOException {
ByteList val = new ByteList(10);
ByteList val = newExternalByteList(10);
byte[] buffer = new byte[len];
int read = bufferedStream.read(buffer, 0, len);
if (read == -1) {
Expand All @@ -1522,7 +1540,7 @@ private IRubyObject readAll() throws IOException {
}

private IRubyObject readAll(int limit) throws IOException {
ByteList val = new ByteList(10);
ByteList val = newExternalByteList(10);
int rest = limit == -1 ? BUFF_SIZE : limit;
byte[] buffer = new byte[rest];
while (rest > 0) {
Expand Down Expand Up @@ -1553,7 +1571,7 @@ private IRubyObject readSize(int len) throws IOException {
offset += read;
} // hmm...
this.position += buffer.length;
return newStr(getRuntime(), new ByteList(buffer, 0, len - toRead, false));
return newStr(getRuntime(), newExternalByteList(buffer, 0, len - toRead, false));
}

@JRubyMethod(name = "lineno=", required = 1)
Expand Down

0 comments on commit 773a155

Please sign in to comment.