protected internal void Print(PrintStream @out, Exception exception, string linePrefix) { if (exception != null) { @out.println(", exception:"); MemoryStream buf = new MemoryStream(); PrintStream sbuf = new PrintStream(buf); exception.printStackTrace(sbuf); sbuf.flush(); StreamReader reader = new StreamReader(new StringReader(buf.ToString())); try { string line = reader.ReadLine(); while (!string.ReferenceEquals(line, null)) { @out.print(linePrefix); @out.print('\t'); @out.println(line); line = reader.ReadLine(); } @out.print(linePrefix); } catch (IOException e) { throw new Exception(e); } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void progressOutput() internal virtual void ProgressOutput() { MemoryStream bout = new MemoryStream(); PrintStream printStream = new PrintStream(bout); ArchiveProgressPrinter progressPrinter = new ArchiveProgressPrinter(printStream); progressPrinter.MaxBytes = 1000; progressPrinter.MaxFiles = 10; progressPrinter.BeginFile(); progressPrinter.AddBytes(5); progressPrinter.EndFile(); progressPrinter.BeginFile(); progressPrinter.AddBytes(50); progressPrinter.AddBytes(50); progressPrinter.PrintOnNextUpdate(); progressPrinter.AddBytes(100); progressPrinter.EndFile(); progressPrinter.BeginFile(); progressPrinter.PrintOnNextUpdate(); progressPrinter.AddBytes(100); progressPrinter.EndFile(); progressPrinter.Done(); progressPrinter.PrintProgress(); printStream.flush(); string output = bout.ToString(); assertEquals(output, "\nFiles: 1/10, data: 0.5%" + "\nFiles: 2/10, data: 20.5%" + "\nFiles: 2/10, data: 20.5%" + "\nFiles: 3/10, data: 30.5%" + "\nFiles: 3/10, data: 30.5%" + "\nDone: 3 files, 305B processed." + Environment.NewLine); }
public virtual void Print(PrintStream @out) { T target = _targetFactory.newInstance(); LinePrinter baseLinePrinter = new PrintStreamLinePrinter(@out, 0); baseLinePrinter.Println("@Test"); baseLinePrinter.Println("public void " + _testName + "() throws Exception"); baseLinePrinter.Println("{"); LinePrinter codePrinter = baseLinePrinter.Indent(); codePrinter.Println("// GIVEN"); _given.print(codePrinter); foreach (Action <T, F> action in _actions) { action.PrintAsCode(target, codePrinter, false); action.Apply(target); } codePrinter.Println(""); codePrinter.Println("// WHEN/THEN"); _failingAction.printAsCode(target, codePrinter, true); baseLinePrinter.Println("}"); @out.flush(); }
public virtual void saveJSGF(URL url) { PrintStream printStream = new PrintStream(new File(url.toURI())); printStream.print(this.toString()); printStream.flush(); printStream.close(); }
public static string Hex(ByteBuffer bytes, int offset, int length, int bytesPerBlock, string groupSep) { MemoryStream outStream = new MemoryStream(); PrintStream @out = new PrintStream(outStream); (new HexPrinter(@out, bytesPerBlock, groupSep)).Append(bytes, offset, length); @out.flush(); return(outStream.ToString()); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private String getProfilerOutput(Profiler profiler) throws InterruptedException private string GetProfilerOutput(Profiler profiler) { profiler.Finish(); MemoryStream buffer = new MemoryStream(); using (PrintStream @out = new PrintStream(buffer)) { profiler.PrintProfile(@out, "Profile"); @out.flush(); } return(buffer.ToString()); }
public override void PercentChanged(int percent) { for (int i = _lastPercentage + 1; i <= percent; i++) { @out.print('.'); if (i % 20 == 0) { @out.printf(" %3d%%%n", i); } } _lastPercentage = percent; @out.flush(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldPrintUserSpecifiedLineNumberFormat() public virtual void ShouldPrintUserSpecifiedLineNumberFormat() { // GIVEN MemoryStream outStream = new MemoryStream(); PrintStream @out = new PrintStream(outStream); HexPrinter printer = (new HexPrinter(@out)).WithLineNumberFormat(5, "[", "]"); // WHEN for (sbyte value = 0; value < 40; value++) { printer.Append(value); } // THEN @out.flush(); assertEquals(format("[0x00000]" + "00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F " + "10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F%n" + "[0x00001]" + "20 21 22 23 24 25 26 27"), outStream.ToString()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotGroupingWhenBytesPerGroupIsGreaterThanBytesPerLine() public virtual void ShouldNotGroupingWhenBytesPerGroupIsGreaterThanBytesPerLine() { // GIVEN MemoryStream outStream = new MemoryStream(); PrintStream @out = new PrintStream(outStream); HexPrinter printer = (new HexPrinter(@out)).WithBytesPerLine(12).withBytesPerGroup(100); // WHEN for (sbyte value = 0; value < 30; value++) { printer.Append(value); } // THEN @out.flush(); assertEquals(format("00 01 02 03 04 05 06 07 08 09 0A 0B%n" + "0C 0D 0E 0F 10 11 12 13 14 15 16 17%n" + "18 19 1A 1B 1C 1D"), outStream.ToString()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldPrintUserSpecifiedBytesGroupingFormat() public virtual void ShouldPrintUserSpecifiedBytesGroupingFormat() { // GIVEN MemoryStream outStream = new MemoryStream(); PrintStream @out = new PrintStream(outStream); HexPrinter printer = (new HexPrinter(@out)).WithBytesGroupingFormat(12, 4, ", "); // WHEN for (sbyte value = 0; value < 30; value++) { printer.Append(value); } // THEN @out.flush(); assertEquals(format("00 01 02 03, 04 05 06 07, 08 09 0A 0B%n" + "0C 0D 0E 0F, 10 11 12 13, 14 15 16 17%n" + "18 19 1A 1B, 1C 1D"), outStream.ToString()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldPrintACoupleOfLines() public virtual void ShouldPrintACoupleOfLines() { // GIVEN MemoryStream outStream = new MemoryStream(); PrintStream @out = new PrintStream(outStream); HexPrinter printer = new HexPrinter(@out); // WHEN for (sbyte value = 0; value < 40; value++) { printer.Append(value); } // THEN @out.flush(); assertEquals(format("00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F " + "10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F%n" + "20 21 22 23 24 25 26 27"), outStream.ToString()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldStartFromUserSpecifiedLineNumber() public virtual void ShouldStartFromUserSpecifiedLineNumber() { // GIVEN MemoryStream outStream = new MemoryStream(); PrintStream @out = new PrintStream(outStream); HexPrinter printer = (new HexPrinter(@out)).WithLineNumberDigits(2).withLineNumberOffset(0xA8); // WHEN for (sbyte value = 0; value < 40; value++) { printer.Append(value); } // THEN @out.flush(); assertEquals(format("@ 0xA8: " + "00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F " + "10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F%n" + "@ 0xA9: " + "20 21 22 23 24 25 26 27"), outStream.ToString()); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void shouldPrint(String command, String... expectedResultContaining) throws Exception private void ShouldPrint(string command, params string[] expectedResultContaining) { // GIVEN File from = Directory.directory("from"); File to = Directory.directory("to"); DatabaseWithSomeTransactions(to); MemoryStream byteArrayOut = new MemoryStream(); PrintStream @out = new PrintStream(byteArrayOut); DatabaseRebuildTool tool = new DatabaseRebuildTool(Input(command, "exit"), @out, NULL_PRINT_STREAM); // WHEN tool.Run("--from", from.AbsolutePath, "--to", to.AbsolutePath, "-i"); // THEN @out.flush(); string dump = StringHelper.NewString(byteArrayOut.toByteArray()); foreach (string @string in expectedResultContaining) { assertThat("dump from command '" + command + "'", dump, containsString(@string)); } }
protected internal static string BeginningOfBufferAsHexString(ChannelBuffer buffer, int maxBytesToPrint) { // read buffer from pos 0 - writeIndex int prevIndex = buffer.readerIndex(); buffer.readerIndex(0); try { MemoryStream byteArrayStream = new MemoryStream(buffer.readableBytes()); PrintStream stream = new PrintStream(byteArrayStream); HexPrinter printer = (new HexPrinter(stream)).withLineNumberDigits(4); for (int i = 0; buffer.readable() && i < maxBytesToPrint; i++) { printer.append(buffer.readByte()); } stream.flush(); return(byteArrayStream.ToString()); } finally { buffer.readerIndex(prevIndex); } }
public override void flush() { base.flush(); _second.flush(); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public static void main(String[] args) throws IOException public static void Main(string[] args) { Scanner inputReader = new Scanner(Console.In); // Get the inputs Console.WriteLine("Player Name: "); string inputName = inputReader.next(); Console.WriteLine("What is the new Score: "); int inputScore = inputReader.Next(); File myFile = new File("newHighScore.txt"); if (myFile.exists()) { myFile.delete(); } myFile.createNewFile(); PrintStream stream = new PrintStream(myFile); File userFile = new File("HighScore.txt"); if (userFile.exists()) { int playerCount = 0; Scanner fileReader = new Scanner(userFile); while (fileReader.hasNext()) { string playerName = fileReader.next(); int playerScore = fileReader.Next(); // Check if the new score is higher than this player score if (inputScore > playerScore) { stream.println(inputName + " " + inputScore); playerCount++; // Set inputScore to 0 so that it will not come in here again inputScore = 0; } // Check that we only write for 5 players if (playerCount < 5) { stream.println(playerName + " " + playerScore); playerCount++; } } stream.flush(); stream.close(); fileReader.close(); } File backupFile = new File("backupHighScore.txt"); if (backupFile.exists()) { backupFile.delete(); } userFile.renameTo(backupFile); myFile.renameTo(userFile); // verify content Scanner reader = new Scanner(userFile); while (reader.hasNextLine()) { Console.WriteLine(reader.nextLine()); } reader.close(); }