RpcInputStream extends FileInputStream { @Override public int read() throws IOException { throw new UnimplementedError("RpcInputStream.read()"); } RpcInputStream(RpcPerforceFile file, Charset fromCharset); @Override void close(); @Override int read(); @Override int read(byte[] targetBytes, int targetOffset, int targetLen); @Override int read(byte[] targetBytes);  }
@Test public void testRead() throws Exception { assertThrows(UnimplementedError.class, () -> rpcInputStream.read()); }
@Test public void testReadForTargetBytesTargetOffsetTargetLen_throw_exception_if_targetBytes_isNull() throws Exception { assertThrows(NullPointerError.class, () -> rpcInputStream.read(null, 1, 10)); }
@Test public void testReadForTargetBytesTargetOffsetTargetLen_throw_exception_if_offset_less_than_zero() throws Exception { byte[] targetBytes = new byte[1001]; assertThrows(P4JavaError.class, () -> rpcInputStream.read(targetBytes, -1, 10)); }
@Test public void testReadForTargetBytesTargetOffsetTargetLen_throw_exception_if_target_length_less_than_zero() throws Exception { byte[] targetBytes = new byte[1001]; assertThrows(P4JavaError.class, () -> rpcInputStream.read(targetBytes, 0, -1)); }
@Test public void testReadForTargetBytesTargetOffsetTargetLen_throw_exception_if_target_length_great_than_length_of_targetBytes() throws Exception { byte[] targetBytes = new byte[10]; assertThrows(P4JavaError.class, () -> rpcInputStream.read(targetBytes, 1, 15)); }
@Test public void testReadUtf16LEWithBomAndUnixLineEnding() throws IOException, FileEncoderException { File mockFile = tmpDir.newFile("utf-16le_with_bom_unix_line_ending_ko.txt"); P4ExtFileUtils.extractResource(this, "com/perforce/p4java/common/io/utf-16le_with_bom_unix_line_ending_ko.txt", mockFile, false); mockFileName = mockFile.getAbsolutePath(); file = new RpcPerforceFile(mockFileName, RpcPerforceFileType.FST_UTF16); rpcInputStream = new RpcInputStream(file, StandardCharsets.UTF_16LE); byte[] targetBytes = new byte[1001]; int read = rpcInputStream.read(targetBytes, 0, 1000); int fileLengthExcludeBom = 343; assertThat(read, is(fileLengthExcludeBom)); }
@Test public void testReadUtf16LEWithBomAndWinLineEnding() throws IOException, FileEncoderException { File mockFile = tmpDir.newFile("utf_16LE_win_line_ending.txt"); P4ExtFileUtils.extractResource(this, "com/perforce/p4java/common/io/utf_16LE_win_line_ending.txt", mockFile, true); mockFileName = mockFile.getAbsolutePath(); file = new RpcPerforceFile(mockFileName, RpcPerforceFileType.FST_UTF16, ClientLineEnding.FST_L_CRLF); rpcInputStream = new RpcInputStream(file, StandardCharsets.UTF_16LE); byte[] targetBytes = new byte[1001]; int read = rpcInputStream.read(targetBytes, 0, 1000); assertThat(read, is(5)); file.setFileType(RpcPerforceFileType.FST_UTF16); rpcInputStream = new RpcInputStream(file, null); read = rpcInputStream.read(targetBytes, 0, 1000); int fileLengthExcludeBom = Files.readAllBytes(file.toPath()).length - 2; assertThat(read, is(fileLengthExcludeBom)); }
@Test public void testReadHasUtf16LEBomButItaAudioFile() throws IOException, FileEncoderException { File file = tmpDir.newFile("file_has_utf_16LE_bom_but_its_actually_a_audio_file.mp1"); P4ExtFileUtils.extractResource(this, "com/perforce/p4java/common/io/file_has_utf_16LE_bom_but_its_actually_a_audio_file.mp1", file, false); mockFileName = file.getPath(); this.file = new RpcPerforceFile(mockFileName, RpcPerforceFileType.FST_BINARY); rpcInputStream = new RpcInputStream(this.file, null); int length = (int) file.length(); byte[] targetBytes = new byte[length]; int read = rpcInputStream.read(targetBytes, 0, length); assertThat(read, is(length)); }
@Test public void testRead() throws Exception { expectThrows(UnimplementedError.class, () -> rpcInputStream.read()); }
@Test public void testReadForTargetBytesTargetOffsetTargetLen_throw_exception_if_targetBytes_isNull() throws Exception { expectThrows(NullPointerError.class, () -> rpcInputStream.read(null, 1, 10)); }
@Test public void testReadForTargetBytesTargetOffsetTargetLen_throw_exception_if_offset_less_than_zero() throws Exception { byte[] targetBytes = new byte[1001]; expectThrows(P4JavaError.class, () -> rpcInputStream.read(targetBytes, -1, 10)); }
@Test public void testReadForTargetBytesTargetOffsetTargetLen_throw_exception_if_target_length_less_than_zero() throws Exception { byte[] targetBytes = new byte[1001]; expectThrows(P4JavaError.class, () -> rpcInputStream.read(targetBytes, 0, -1)); }
@Test public void testReadForTargetBytesTargetOffsetTargetLen_throw_exception_if_target_length_great_than_length_of_targetBytes() throws Exception { byte[] targetBytes = new byte[10]; expectThrows(P4JavaError.class, () -> rpcInputStream.read(targetBytes, 1, 15)); }
@Test public void testReadForTargetBytes() throws Exception { byte[] targetBytes = new byte[1001]; int read = rpcInputStream.read(targetBytes); int fileLengthExcludeBom = Files.readAllBytes(file.toPath()).length - 2; assertThat(read, is(fileLengthExcludeBom)); }
@Test public void testReadForTargetBytesTargetOffsetTargetLen_withoutExpectedTextFileType() throws Exception { byte[] targetBytes = new byte[1001]; int read = rpcInputStream.read(targetBytes, 0, 1000); int fileLengthExcludeBom = Files.readAllBytes(file.toPath()).length - 2; assertThat(read, is(fileLengthExcludeBom)); }
@Test public void testReadForTargetBytesTargetOffsetTargetLen_read_from_RpcLineEndFilterInputStream() throws Exception { mockCRLRLineEndingAndUTF8EncodingFile(); byte[] targetBytes = new byte[1001]; int read = rpcInputStream.read(targetBytes, 0, 1000); int expectedLengthAsCRLFWasReplaceByLF = 4; assertThat(read, is(expectedLengthAsCRLFWasReplaceByLF)); }
@Test public void testReadUtf16LEWithBomAndUnixLineEnding() throws IOException, FileEncoderException { mockFileName = loadFileFromClassPath("com/perforce/p4java/common/io/utf-16le_with_bom_unix_line_ending_ko.txt").getPath(); file = new RpcPerforceFile(mockFileName, RpcPerforceFileType.FST_UTF16); rpcInputStream = new RpcInputStream(file, StandardCharsets.UTF_16LE); byte[] targetBytes = new byte[1001]; int read = rpcInputStream.read(targetBytes, 0, 1000); int fileLengthExcludeBom = 343; assertThat(read, is(fileLengthExcludeBom)); }
@Test public void testReadUtf16LEWithBomAndWinLineEnding() throws IOException, FileEncoderException { mockFileName = loadFileFromClassPath("com/perforce/p4java/common/io/utf_16LE_win_line_ending.txt").getPath(); file = new RpcPerforceFile(mockFileName, RpcPerforceFileType.FST_UTF16, ClientLineEnding.FST_L_CRLF); rpcInputStream = new RpcInputStream(file, StandardCharsets.UTF_16LE); byte[] targetBytes = new byte[1001]; int read = rpcInputStream.read(targetBytes, 0, 1000); assertThat(read, is(5)); file.setFileType(RpcPerforceFileType.FST_UTF16); rpcInputStream = new RpcInputStream(file, null); read = rpcInputStream.read(targetBytes, 0, 1000); int fileLengthExcludeBom = Files.readAllBytes(file.toPath()).length - 2; assertThat(read, is(fileLengthExcludeBom)); }
@Test(expected = UnimplementedError.class) public void testRead() throws Exception { rpcInputStream.read(); }
@Test(expected = NullPointerError.class) public void testReadForTargetBytesTargetOffsetTargetLen_throw_exception_if_targetBytes_isNull() throws Exception { rpcInputStream.read(null, 1, 10); }
@Test public void testReadHasUtf16LEBomButItaAudioFile() throws IOException, FileEncoderException { File file = loadFileFromClassPath("com/perforce/p4java/common/io/file_has_utf_16LE_bom_but_its_actually_a_audio_file.mp1"); mockFileName = file.getPath(); this.file = new RpcPerforceFile(mockFileName, RpcPerforceFileType.FST_BINARY); rpcInputStream = new RpcInputStream(this.file, null); int length = (int) file.length(); byte[] targetBytes = new byte[length]; int read = rpcInputStream.read(targetBytes, 0, length); assertThat(read, is(length)); }
@Test(expected = P4JavaError.class) public void testReadForTargetBytesTargetOffsetTargetLen_throw_exception_if_offset_less_than_zero() throws Exception { byte[] targetBytes = new byte[1001]; rpcInputStream.read(targetBytes, -1, 10); }
@Test(expected = P4JavaError.class) public void testReadForTargetBytesTargetOffsetTargetLen_throw_exception_if_target_length_less_than_zero() throws Exception { byte[] targetBytes = new byte[1001]; rpcInputStream.read(targetBytes, 0, -1); }
@Test(expected = P4JavaError.class) public void testReadForTargetBytesTargetOffsetTargetLen_throw_exception_if_target_length_great_than_length_of_targetBytes() throws Exception { byte[] targetBytes = new byte[10]; rpcInputStream.read(targetBytes, 1, 15); }
@Test public void testReadUtf16LEWithBomAndUnixLineEnding() throws IOException, FileEncoderException { mockFileName = loadFileFromClassPath( "com/perforce/p4java/common/io/utf-16le_with_bom_unix_line_ending_ko.txt") .getPath(); file = new RpcPerforceFile(mockFileName, RpcPerforceFileType.FST_UTF16); rpcInputStream = new RpcInputStream(file, StandardCharsets.UTF_16LE); byte[] targetBytes = new byte[1001]; int read = rpcInputStream.read(targetBytes, 0, 1000); int fileLengthExcludeBom = 343; assertThat(read, is(fileLengthExcludeBom)); }
@Test public void testReadUtf16LEWithBomAndWinLineEnding() throws IOException, FileEncoderException { mockFileName = loadFileFromClassPath( "com/perforce/p4java/common/io/utf_16LE_win_line_ending.txt").getPath(); file = new RpcPerforceFile(mockFileName, RpcPerforceFileType.FST_UTF16, ClientLineEnding.FST_L_CRLF); rpcInputStream = new RpcInputStream(file, StandardCharsets.UTF_16LE); byte[] targetBytes = new byte[1001]; int read = rpcInputStream.read(targetBytes, 0, 1000); assertThat(read, is(5)); file.setFileType(RpcPerforceFileType.FST_UTF16); rpcInputStream = new RpcInputStream(file, null); read = rpcInputStream.read(targetBytes, 0, 1000); int fileLengthExcludeBom = Files.readAllBytes(file.toPath()).length - 2; assertThat(read, is(fileLengthExcludeBom)); }
@Test public void testReadHasUtf16LEBomButItaAudioFile() throws IOException, FileEncoderException { File file = loadFileFromClassPath( "com/perforce/p4java/common/io/file_has_utf_16LE_bom_but_its_actually_a_audio_file.mp1"); mockFileName = file.getPath(); this.file = new RpcPerforceFile(mockFileName, RpcPerforceFileType.FST_BINARY); rpcInputStream = new RpcInputStream(this.file, null); int length = (int) file.length(); byte[] targetBytes = new byte[length]; int read = rpcInputStream.read(targetBytes, 0, length); assertThat(read, is(length)); }