mirror of https://github.com/apache/lucene.git
SOLR-902 -- FastInputStream#read(byte b[], int off, int len) gives incorrect results when amount left to read is less than buffer size
git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@729834 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3b57a5a624
commit
fd89aab62f
|
@ -118,7 +118,7 @@ New Features
|
|||
optimized distributed faceting refinement by lowering parsing overhead and
|
||||
by making requests and responses smaller.
|
||||
|
||||
25. SOLR-876: WordDelimiterFilter now supports a splitOnNumerics
|
||||
25. SOLR-876: WordDelimiterFilter now supports a splitOnNumerics
|
||||
option, as well as a list of protected terms.
|
||||
(Dan Rosher via hossman)
|
||||
|
||||
|
@ -147,7 +147,7 @@ Bug Fixes
|
|||
|
||||
2. SOLR-771: CoreAdminHandler STATUS should display 'normalized' paths (koji, hossman, shalin)
|
||||
|
||||
3. SOLR-532: WordDelimiterFilter now respects payloads and other attributes of the original Token by
|
||||
3. SOLR-532: WordDelimiterFilter now respects payloads and other attributes of the original Token by
|
||||
using Token.clone() (Tricia Williams, gsingers)
|
||||
|
||||
4. SOLR-805: DisMax queries are not being cached in QueryResultCache (Todd Feak via koji)
|
||||
|
@ -193,7 +193,7 @@ Bug Fixes
|
|||
|
||||
19. SOLR-802: Fix a potential null pointer error in the distributed FacetComponent
|
||||
(David Bowen via ryan)
|
||||
|
||||
|
||||
20. SOLR-346: Use perl regex to improve accuracy of finding latest snapshot in snapinstaller (billa)
|
||||
|
||||
21. SOLR-830: Use perl regex to improve accuracy of finding latest snapshot in snappuller (billa)
|
||||
|
@ -202,6 +202,9 @@ Bug Fixes
|
|||
|
||||
23. SOLR-925: Fixed highlighting on fields with multiValued="true" and termOffsets="true" (koji)
|
||||
|
||||
24. SOLR-902: FastInputStream#read(byte b[], int off, int len) gives incorrect results when amount left to read is less
|
||||
than buffer size (Noble Paul via shalin)
|
||||
|
||||
|
||||
Other Changes
|
||||
----------------------
|
||||
|
|
|
@ -105,7 +105,7 @@ public class FastInputStream extends InputStream implements DataInput {
|
|||
return r;
|
||||
}
|
||||
|
||||
return -1;
|
||||
return r > 0 ? r : -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
/**
|
||||
* 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.solr.common.util;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
/**
|
||||
* Test for FastInputStream.
|
||||
*
|
||||
* @version $Id$
|
||||
* @see org.apache.solr.common.util.FastInputStream
|
||||
*/
|
||||
public class TestFastInputStream {
|
||||
@Test
|
||||
public void testgzip() throws Exception {
|
||||
ByteArrayOutputStream b = new ByteArrayOutputStream();
|
||||
FastOutputStream fos = new FastOutputStream(b);
|
||||
GZIPOutputStream gzos = new GZIPOutputStream(fos);
|
||||
String ss = "Helloooooooooooooooooooo";
|
||||
writeChars(gzos, ss, 0, ss.length());
|
||||
gzos.close();
|
||||
NamedListCodec.writeVInt(10, fos);
|
||||
fos.flushBuffer();
|
||||
GZIPInputStream gzis = new GZIPInputStream(new ByteArrayInputStream(b.toByteArray(), 0, b.size()));
|
||||
char[] cbuf = new char[ss.length()];
|
||||
readChars(gzis, cbuf, 0, ss.length());
|
||||
assertEquals(new String(cbuf), ss);
|
||||
System.out.println("passes w/o FastInputStream");
|
||||
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(b.toByteArray(), 0, b.size());
|
||||
gzis = new GZIPInputStream(new FastInputStream(bis));
|
||||
cbuf = new char[ss.length()];
|
||||
readChars(gzis, cbuf, 0, ss.length());
|
||||
assertEquals(new String(cbuf), ss);
|
||||
System.out.println("passes w FastInputStream");
|
||||
|
||||
|
||||
}
|
||||
|
||||
//code copied from NamedListCodec#readChars
|
||||
public static void readChars(InputStream in, char[] buffer, int start, int length)
|
||||
throws IOException {
|
||||
final int end = start + length;
|
||||
for (int i = start; i < end; i++) {
|
||||
int b = in.read();
|
||||
if ((b & 0x80) == 0)
|
||||
buffer[i] = (char) b;
|
||||
else if ((b & 0xE0) != 0xE0) {
|
||||
buffer[i] = (char) (((b & 0x1F) << 6)
|
||||
| (in.read() & 0x3F));
|
||||
} else
|
||||
buffer[i] = (char) (((b & 0x0F) << 12)
|
||||
| ((in.read() & 0x3F) << 6)
|
||||
| (in.read() & 0x3F));
|
||||
}
|
||||
}
|
||||
|
||||
// code copied rfrom NamedlistCode#writechars
|
||||
public static void writeChars(OutputStream os, String s, int start, int length) throws IOException {
|
||||
final int end = start + length;
|
||||
for (int i = start; i < end; i++) {
|
||||
final int code = (int) s.charAt(i);
|
||||
if (code >= 0x01 && code <= 0x7F)
|
||||
os.write(code);
|
||||
else if (((code >= 0x80) && (code <= 0x7FF)) || code == 0) {
|
||||
os.write(0xC0 | (code >> 6));
|
||||
os.write(0x80 | (code & 0x3F));
|
||||
} else {
|
||||
os.write(0xE0 | (code >>> 12));
|
||||
os.write(0x80 | ((code >> 6) & 0x3F));
|
||||
os.write(0x80 | (code & 0x3F));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue