-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
修复HDFS上的readBytesFromOtherInputStream:#536 (comment)
- Loading branch information
Showing
2 changed files
with
48 additions
and
5 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,34 @@ | ||
package com.hankcs.hanlp.corpus.io; | ||
|
||
import junit.framework.TestCase; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.util.Random; | ||
|
||
public class IOUtilTest extends TestCase | ||
{ | ||
public void testReadBytesFromOtherInputStream() throws Exception | ||
{ | ||
Random random = new Random(System.currentTimeMillis()); | ||
byte[] originalData = new byte[1024 * 1024]; // 1MB | ||
random.nextBytes(originalData); | ||
ByteArrayInputStream is = new ByteArrayInputStream(originalData){ | ||
@Override | ||
public synchronized int available() | ||
{ | ||
int realAvailable = super.available(); | ||
if (realAvailable > 0) | ||
{ | ||
return 2048; // 模拟某些网络InputStream | ||
} | ||
return realAvailable; | ||
} | ||
}; | ||
byte[] readData = IOUtil.readBytesFromOtherInputStream(is); | ||
assertEquals(originalData.length, readData.length); | ||
for (int i = 0; i < originalData.length; i++) | ||
{ | ||
assertEquals(originalData[i], readData[i]); | ||
} | ||
} | ||
} |