private boolean isCompleteLineWritten(byte[] buffer, int indexLastByteWritten) { byte[] separator = getProperty("line.separator") .getBytes(defaultCharset()); int indexFirstByteOfSeparator = indexLastByteWritten - separator.length + 1; return indexFirstByteOfSeparator >= 0 && contains(buffer, separator, indexFirstByteOfSeparator); }
/** * Set the text that is returned by {@code System.in}. You can * provide multiple texts. In that case the texts are concatenated. * * @param texts a list of texts. * @deprecated please use {@link #provideLines(String...)} */ @Deprecated public void provideText(String... texts) { systemInMock.provideText(join(texts)); }
@Override public int read(byte[] buffer, int offset, int len) throws IOException { if (buffer == null) throw new NullPointerException(); else if (offset < 0 || len < 0 || len > buffer.length - offset) throw new IndexOutOfBoundsException(); else if (len == 0) return 0; else return readNextLine(buffer, offset, len); }
private int readNextLine(byte[] buffer, int offset, int len) throws IOException { int c = read(); if (c == -1) return -1; buffer[offset] = (byte) c; int i = 1; for (; (i < len) && !isCompleteLineWritten(buffer, i - 1); ++i) { byte read = (byte) read(); if (read == -1) break; else buffer[offset + i] = read; } return i; }
private int readNextLine(byte[] buffer, int offset, int len) throws IOException { int c = read(); if (c == -1) return -1; buffer[offset] = (byte) c; int i = 1; for (; (i < len) && !isCompleteLineWritten(buffer, i - 1); ++i) { byte read = (byte) read(); if (read == -1) break; else buffer[offset + i] = read; } return i; }
private int readNextLine(byte[] buffer, int offset, int len) throws IOException { int c = read(); if (c == -1) return -1; buffer[offset] = (byte) c; int i = 1; for (; (i < len) && !isCompleteLineWritten(buffer, i - 1); ++i) { byte read = (byte) read(); if (read == -1) break; else buffer[offset + i] = read; } return i; }
/** * Specify a {@code RuntimeException} that is thrown by {@code System.in}. * If you call {@link #provideLines(String...)} or * {@link #provideText(String...)} in addition then the exception is thrown * after the text has been read from {@code System.in}. * * @param exception the {@code RuntimeException} that is thrown. * @see #throwExceptionOnInputEnd(IOException) * @throws IllegalStateException if * {@link #throwExceptionOnInputEnd(IOException)} has been called before. */ public void throwExceptionOnInputEnd(RuntimeException exception) { systemInMock.throwExceptionOnInputEnd(exception); }
/** * Specify an {@code IOException} that is thrown by {@code System.in}. If * you call {@link #provideLines(String...)} or * {@link #provideText(String...)} in addition then the exception is thrown * after the text has been read from {@code System.in}. * * @param exception the {@code IOException} that is thrown. * @see #throwExceptionOnInputEnd(RuntimeException) * @throws IllegalStateException if * {@link #throwExceptionOnInputEnd(RuntimeException)} has been called before. */ public void throwExceptionOnInputEnd(IOException exception) { systemInMock.throwExceptionOnInputEnd(exception); }
/** * Specify a {@code RuntimeException} that is thrown by {@code System.in}. * If you call {@link #provideLines(String...)} or * {@link #provideText(String...)} in addition then the exception is thrown * after the text has been read from {@code System.in}. * * @param exception the {@code RuntimeException} that is thrown. * @see #throwExceptionOnInputEnd(IOException) * @throws IllegalStateException if * {@link #throwExceptionOnInputEnd(IOException)} has been called before. */ public void throwExceptionOnInputEnd(RuntimeException exception) { systemInMock.throwExceptionOnInputEnd(exception); }
/** * Specify an {@code IOException} that is thrown by {@code System.in}. If * you call {@link #provideLines(String...)} or * {@link #provideText(String...)} in addition then the exception is thrown * after the text has been read from {@code System.in}. * * @param exception the {@code IOException} that is thrown. * @see #throwExceptionOnInputEnd(RuntimeException) * @throws IllegalStateException if * {@link #throwExceptionOnInputEnd(RuntimeException)} has been called before. */ public void throwExceptionOnInputEnd(IOException exception) { systemInMock.throwExceptionOnInputEnd(exception); }
/** * Specify a {@code RuntimeException} that is thrown by {@code System.in}. * If you call {@link #provideLines(String...)} or * {@link #provideText(String...)} in addition then the exception is thrown * after the text has been read from {@code System.in}. * * @param exception the {@code RuntimeException} that is thrown. * @see #throwExceptionOnInputEnd(IOException) * @throws IllegalStateException if * {@link #throwExceptionOnInputEnd(IOException)} has been called before. */ public void throwExceptionOnInputEnd(RuntimeException exception) { systemInMock.throwExceptionOnInputEnd(exception); }
/** * Specify an {@code IOException} that is thrown by {@code System.in}. If * you call {@link #provideLines(String...)} or * {@link #provideText(String...)} in addition then the exception is thrown * after the text has been read from {@code System.in}. * * @param exception the {@code IOException} that is thrown. * @see #throwExceptionOnInputEnd(RuntimeException) * @throws IllegalStateException if * {@link #throwExceptionOnInputEnd(RuntimeException)} has been called before. */ public void throwExceptionOnInputEnd(IOException exception) { systemInMock.throwExceptionOnInputEnd(exception); }
/** * Set the lines that are returned by {@code System.in}. * {@code System.getProperty("line.separator")} is used for the end * of line. * * @param lines a list of lines. */ public void provideLines(String... lines) { systemInMock.provideText(joinLines(lines)); }
@Override public int read() throws IOException { int character = currentReader.read(); if (character == -1) handleEmptyReader(); return character; }
/** * Set the text that is returned by {@code System.in}. You can * provide multiple texts. In that case the texts are concatenated. * * @param texts a list of texts. * @deprecated please use {@link #provideLines(String...)} */ @Deprecated public void provideText(String... texts) { systemInMock.provideText(join(texts)); }
@Override public int read(byte[] buffer, int offset, int len) throws IOException { if (buffer == null) throw new NullPointerException(); else if (offset < 0 || len < 0 || len > buffer.length - offset) throw new IndexOutOfBoundsException(); else if (len == 0) return 0; else return readNextLine(buffer, offset, len); }
/** * Set the text that is returned by {@code System.in}. You can * provide multiple texts. In that case the texts are concatenated. * * @param texts a list of texts. * @deprecated please use {@link #provideLines(String...)} */ @Deprecated public void provideText(String... texts) { systemInMock.provideText(join(texts)); }
private boolean isCompleteLineWritten(byte[] buffer, int indexLastByteWritten) { byte[] separator = getProperty("line.separator").getBytes(); int indexFirstByteOfSeparator = indexLastByteWritten - separator.length + 1; return indexFirstByteOfSeparator >= 0 && contains(buffer, separator, indexFirstByteOfSeparator); }
private boolean isCompleteLineWritten(byte[] buffer, int indexLastByteWritten) { byte[] separator = getProperty("line.separator").getBytes(); int indexFirstByteOfSeparator = indexLastByteWritten - separator.length + 1; return indexFirstByteOfSeparator >= 0 && contains(buffer, separator, indexFirstByteOfSeparator); }
/** * Set the lines that are returned by {@code System.in}. * {@code System.getProperty("line.separator")} is used for the end * of line. * * @param lines a list of lines. */ public void provideLines(String... lines) { systemInMock.provideText(joinLines(lines)); }