- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - allow writing per character, auto flush per line
2188
function chars(target, splitExp) {
		var inst = core.base();
		inst.textBuffer = '';
		inst.enabled = true;
		inst.splitExp = (splitExp || /(.*?)\r?\n/g);

		inst.useTarget = function (target) {
			inst.target = (target || {
				// dummy
				writeln: function () {
					//nothing
				}
			});
		};

		inst.clear = function () {
			inst.textBuffer = '';
			inst.splitExp.lastIndex = 0;
		};

		inst.write = function (str) {
			if (str === '') {
				return;
			}
			if (inst.enabled) {
				//fast path
				inst.textBuffer += str;
				inst.flush(true);
			}
		};

		inst.writeln = function (str) {
			if (inst.enabled) {
				//fast path
				if (arguments.length === 0) {
					inst.textBuffer += '\n';
				}
				else {
					inst.textBuffer += str + '\n';
				}
				inst.flush(true);
			}
		};

		inst.flush = function (linesOnly) {
			if (inst.textBuffer.length > 0) {
				var match;
				var end = 0;
				//TODO verify if we really need a capture group?
				//     instead not search for line break and use index + length of match + substing
				while ((match = inst.splitExp.exec(inst.textBuffer))) {
					inst.target.writeln(match[1]);
					end = match.index + (match[0].length || 1);
					inst.splitExp.lastIndex = end;
				}
				if (end > 0) {
					inst.textBuffer = inst.textBuffer.substring(end);
					inst.splitExp.lastIndex = 0;
				}
				if (!linesOnly && inst.textBuffer.length > 0) {
					inst.target.writeln(inst.textBuffer);
					inst.textBuffer = 0;
					inst.splitExp.lastIndex = 0;
				}
			}
		};

		inst.has = function () {
			return inst.textBuffer.length > 0;
		};

		inst.toString = function () {
			return '<miniwrite-chars>';
		};
		// use target
		inst.useTarget(target);
		return inst;
	}
1117769
function eachLine(str, callback)
    {
        var lines = splitLines(str);

        for (var i = 0; i < lines.length; i++)
            lines[i] = callback(lines[i], i);

        // include \r to enable copy-paste on windows (ie8) without getting everything on one line
        return lines.join('\r\n');
    }
63319
@Override
    public void flush() {

        PrintWriter out = null;
        try {
            try {
                out = new PrintWriter(Utils.createFile(dir, file), "UTF-8");
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            String contents = getBuffer().toString();
            out.write(processor.apply(contents));
        } finally {
            closeQuietly(out);
        }
    }
105888
async def writelines(self, lines, eof = False, buffering = True):
        
        for l in lines:
            await self.write(l, False, buffering)
        if eof:
            await self.write(b'', eof, buffering)
194864
protected void flushIfPossible() throws IOException {

        // TODO: do not flush if wasn't requested by underlying application
        if (null != bufferedServletOutputStream) bufferedServletOutputStream.setLastChunk();

        if (null != writer) writer.flushIfOpen();
        else if (null != outputStream) outputStream.flushIfOpen();
        else {
            if (!isCommitted()) {
                notifyBeforeCommit();
            }
            notifyBeforeClose();
        }
    }
345072
function flush(writeTo) {
    var outputTo = bufferLen + matchStart - chunkLength;

    while (outputTo > 0 && outputTo > bufferStart) {
      if (outputTo > buffer[0].length-1) {
        var part = buffer.shift();
        outputBuffer.push(part.slice(bufferStart));

        bufferStart = Math.max(0, bufferStart - part.length);
        bufferLen -= part.length;
        outputTo -= part.length;
      } else {
        outputBuffer.push(buffer[0].slice(bufferStart, outputTo));
        bufferStart = outputTo;
        break;
      }
    }
    if (writeTo) {
      // Output everything ready as one chunk
      writeTo.push(outputBuffer.join(''));
      outputBuffer.length = 0;
    }
  }
1043540
def write(self, output='', flush=True, position=0):
        

        if self.enabled:

            term = self.term
            stream = self.stream

            try:
                term.move_to(0, term.height - position)
                # Include \r and term call to cover most conditions
                if NEEDS_UNICODE_HELP:  # pragma: no cover (Version dependent 2.6)
                    encoding = stream.encoding or 'UTF-8'
                    stream.write(('\r' + term.clear_eol + output).encode(encoding))
                else:  # pragma: no cover (Version dependent >= 2.7)
                    stream.write('\r' + term.clear_eol + output)

            finally:
                # Reset position and scrolling
                self._set_scroll_area()
                if flush:
                    stream.flush()
758481
private void flush(boolean isEnd)
  {
    if (_startOffset == _offset && _bufferSize == 0) {
      if (! isCommitted() || isEnd) {
        flush(null, isEnd);
        _startOffset = bufferStart();
        _offset = _startOffset;
      }
      return;
    }

    int sublen = _offset - _startOffset;
    _tBuf.length(_offset);
    _contentLength += _offset - _startOffset;
    _bufferSize = 0;
    
    if (_startOffset > 0) {
      fillChunkHeader(_tBuf, sublen);
    }
    
    flush(_tBuf, isEnd);

    if (! isEnd) {
      _tBuf = TempBuffer.create();
    
      _startOffset = bufferStart();
      _offset = _startOffset;

      _tBuf.length(_offset);
      
      _buffer = _tBuf.buffer();
    }
    else {
      _tBuf = null;
    }
  }
296054
def enable_writes(self):
        """"""
        self.write_buffer = []
        self.flush_lock = threading.RLock()
        self.flush_thread = FlushThread(self.max_batch_time,
                                        self._flush_writes)
133092
def write(p, line):
    """"""
    log.debug('%s <- %r', p.args, line)
    p.stdin.write(line)
    p.stdin.flush()
1300180
protected final void flushBuffer() throws IOException {
        if (bufferSize == 0)
            return;
        flushed = true;
        // defect 312981 begin
        //ensureOpen();
    	if (closed) {
    	    throw new IOException("Stream closed");
        }
        // defect 312981 end

        if (nextChar == 0) {
            //PK90190 - start 
            //add check for property to create the writer even when the buffer is empty
            if (WCCustomProperties.GET_WRITER_ON_EMPTY_BUFFER) {
                initOut();
            }
            //PK90190 - end
            return;
        }
        initOut();
        out.write(cb, 0, nextChar);
        nextChar = 0;
    }
1059589
void flush(ByteBuf out) {
        final int bitCount = this.bitCount;

        if (bitCount > 0) {
            final long bitBuffer = this.bitBuffer;
            final int shiftToRight = 64 - bitCount;

            if (bitCount <= 8) {
                out.writeByte((int) (bitBuffer >>> shiftToRight << 8 - bitCount));
            } else if (bitCount <= 16) {
                out.writeShort((int) (bitBuffer >>> shiftToRight << 16 - bitCount));
            } else if (bitCount <= 24) {
                out.writeMedium((int) (bitBuffer >>> shiftToRight << 24 - bitCount));
            } else {
                out.writeInt((int) (bitBuffer >>> shiftToRight << 32 - bitCount));
            }
        }
    }
1364321
def write(self, output):
        
        self._stream.write(output)

        if self._auto_flush:
            self._stream.flush()
1172875
void flushBuffer() throws IOException {
        synchronized (lock) {
            ensureOpen();
            if (nextChar == 0)
                return;
            out.write(cb, 0, nextChar);
            nextChar = 0;
        }
    }
1298809
private void flush(final Collection<Writer> writers) {
		for (Writer writer : writers) {
			try {
				writer.flush();
			} catch (Exception ex) {
				InternalLogger.log(Level.ERROR, ex, "Failed to flush writer");
			}
		}
	}
966463
def write(self, s, flush=True):
        
        return self._writeb(s, flush=flush)
730664
public function write() {
        // Determine the width of the last column.
        $columnWidths = array_sum($this->columnWidths);
        $totalWidth = $this->indent + $columnWidths + $this->padding * (count($this->columnWidths) - 1);

        $lastWidth = end($this->columnWidths) + $this->maxWidth - $totalWidth;
        $lastWidth = max($lastWidth, 10); // min width of 10
        $this->columnWidths[count($this->columnWidths) - 1] = $lastWidth;

        // Loop through each row and write it.
        foreach ($this->rows as $row) {
            $rowLines = [];
            $lineCount = 0;

            // Split the cells into lines.
            foreach ($row as $i => $cell) {
                list($text,) = $cell;
                $width = $this->columnWidths[$i];

                $lines = Cli::breakLines($text, $width, $i < count($this->columnWidths) - 1);
                $rowLines[] = $lines;
                $lineCount = max($lineCount, count($lines));
            }

            // Write all of the lines.
            for ($i = 0; $i < $lineCount; $i++) {
                foreach ($rowLines as $j => $lines) {
                    $padding = $j === 0 ? $this->indent : $this->padding;

                    if (isset($lines[$i])) {
                        if ($this->formatOutput) {
                            if(isset($row[$j])) {
                                $wrap = $row[$j][1];
                            } else {
                                // if we're out of array, use the latest wraps
                                $wrap = $row[count($row)-1][1];
                            }

                            echo str_repeat(' ', $padding).$wrap[0].$lines[$i].$wrap[1];
                        } else {
                            echo str_repeat(' ', $padding).$lines[$i];
                        }
                    } elseif ($j < count($this->columnWidths) - 1) {
                        // This is an empty line. Write the spaces.
                        echo str_repeat(' ', $padding + $this->columnWidths[$j]);
                    }
                }
                echo PHP_EOL;
            }
        }
    }