Java Code Examples for java.io.PrintStream#write()

The following examples show how to use java.io.PrintStream#write() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: P4JavaTestCase.java    From p4ic4idea with Apache License 2.0 7 votes vote down vote up
protected void mangleTextFile(int severity, InputStream inFile, PrintStream outFile) {
    if ((inFile == null) || (outFile == null)) {
        fail("null input or output stream passed to mangleTextFile");
    }

    byte[] inBuf = new byte[2048];
    int bytesRead = 0;
    try {
        while ((bytesRead = inFile.read(inBuf)) > 0) {
            if (severity > 0) {
                for (int i = 0; i < bytesRead; i++) {
                    if ((i % severity) == 0) {
                        if ((inBuf[i] >= ' ') && (inBuf[i] <= '~')) {
                            inBuf[i] = getRandomCharByte();
                        }
                    }
                }
            }
            outFile.write(inBuf, 0, bytesRead);
        }
    } catch (IOException ioexc) {
        fail("I/O exception in mangleTextFile: " + ioexc.getLocalizedMessage());
    }
}
 
Example 2
Source File: HexDumpEncoder.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
static void hexDigit(PrintStream p, byte x) {
    char c;

    c = (char) ((x >> 4) & 0xf);
    if (c > 9)
        c = (char) ((c-10) + 'A');
    else
        c = (char)(c + '0');
    p.write(c);
    c = (char) (x & 0xf);
    if (c > 9)
        c = (char)((c-10) + 'A');
    else
        c = (char)(c + '0');
    p.write(c);
}
 
Example 3
Source File: HexDumpEncoder.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
static void hexDigit(PrintStream p, byte x) {
    char c;

    c = (char) ((x >> 4) & 0xf);
    if (c > 9)
        c = (char) ((c-10) + 'A');
    else
        c = (char)(c + '0');
    p.write(c);
    c = (char) (x & 0xf);
    if (c > 9)
        c = (char)((c-10) + 'A');
    else
        c = (char)(c + '0');
    p.write(c);
}
 
Example 4
Source File: HexDumpEncoder.java    From davmail with GNU General Public License v2.0 6 votes vote down vote up
static void hexDigit(PrintStream p, byte x) {
    char c;

    c = (char) ((x >> 4) & 0xf);
    if (c > 9)
        c = (char) ((c-10) + 'A');
    else
        c = (char)(c + '0');
    p.write(c);
    c = (char) (x & 0xf);
    if (c > 9)
        c = (char)((c-10) + 'A');
    else
        c = (char)(c + '0');
    p.write(c);
}
 
Example 5
Source File: HexDumpEncoder.java    From Raccoon with Apache License 2.0 6 votes vote down vote up
static void hexDigit(PrintStream p, byte x) {
    char c;

    c = (char) ((x >> 4) & 0xf);
    if (c > 9)
        c = (char) ((c-10) + 'A');
    else
        c = (char)(c + '0');
    p.write(c);
    c = (char) (x & 0xf);
    if (c > 9)
        c = (char)((c-10) + 'A');
    else
        c = (char)(c + '0');
    p.write(c);
}
 
Example 6
Source File: P4JavaTestCase.java    From p4ic4idea with Apache License 2.0 6 votes vote down vote up
protected void mangleTextFile(int severity, InputStream inFile, PrintStream outFile) {
	if ((inFile == null) || (outFile == null)) {
		fail("null input or output stream passed to mangleTextFile");
	}

	byte[] inBuf = new byte[2048];
	int bytesRead = 0;
	try {
		while ((bytesRead = inFile.read(inBuf)) > 0) {
			if (severity > 0) {
				for (int i = 0; i < bytesRead; i++) {
					if ((i % severity) == 0) {
						if ((inBuf[i] >= ' ') && (inBuf[i] <= '~')) {
							inBuf[i] = getRandomCharByte();
						}
					}
				}
			}
			outFile.write(inBuf, 0, bytesRead);
		}
	} catch (IOException ioexc) {
		fail("I/O exception in mangleTextFile: " + ioexc.getLocalizedMessage());
	}
}
 
Example 7
Source File: HexDumpEncoder.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
static void hexDigit(PrintStream p, byte x) {
    char c;

    c = (char) ((x >> 4) & 0xf);
    if (c > 9)
        c = (char) ((c-10) + 'A');
    else
        c = (char)(c + '0');
    p.write(c);
    c = (char) (x & 0xf);
    if (c > 9)
        c = (char)((c-10) + 'A');
    else
        c = (char)(c + '0');
    p.write(c);
}
 
Example 8
Source File: HexDumpEncoder.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
static void hexDigit(PrintStream p, byte x) {
    char c;

    c = (char) ((x >> 4) & 0xf);
    if (c > 9)
        c = (char) ((c-10) + 'A');
    else
        c = (char)(c + '0');
    p.write(c);
    c = (char) (x & 0xf);
    if (c > 9)
        c = (char)((c-10) + 'A');
    else
        c = (char)(c + '0');
    p.write(c);
}
 
Example 9
Source File: HeaderedArchiveRecord.java    From webarchive-commons with Apache License 2.0 6 votes vote down vote up
public void dumpHttpHeader(final PrintStream stream) throws IOException {
    if (this.contentHeaderStream == null) {
        return;
    }
    // Dump the httpHeaderStream to STDOUT
    for (int available = this.contentHeaderStream.available();
        this.contentHeaderStream != null
            && (available = this.contentHeaderStream.available()) > 0;) {
        // We should be in this loop only once and should do this
        // buffer allocation once.
        byte[] buffer = new byte[available];
        // The read nulls out httpHeaderStream when done with it so
        // need check for null in the loop control line.
        int read = read(buffer, 0, available);
        stream.write(buffer, 0, read);
    }
}
 
Example 10
Source File: TextRecordWriter.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void startPartition(WritePartition partition) throws Exception {

  if(this.partition != null){
    close();
  }

  this.partition = partition;
  // open a new file for writing data with new schema
  try {
    this.path = fs.canonicalizePath(partition.qualified(location, prefix + "_" + index + "." + extension));
    dos = new DataOutputStream(fs.create(path));
    stream = new PrintStream(dos);
    stream.write(ByteOrderMark.UTF_8.getBytes(), 0, ByteOrderMark.UTF_8.length());
    logger.debug("Created file: {}", path);
  } catch (IOException e) {
    throw UserException.dataWriteError(e)
      .message("Failure while attempting to write file %s.", path)
      .build(logger);
  }
  index++;

  String columns = Joiner.on(fieldDelimiter).join(columnNames);
  stream.print(columns);
  stream.print(lineDelimiter);

}
 
Example 11
Source File: URLDigestFinalPositionWriter.java    From BUbiNG with Apache License 2.0 5 votes vote down vote up
@Override
public void write(final WarcRecord warcRecord, final long storePosition, final PrintStream out) throws IOException {
	if (repeatedSet.contains(storeIndexMask | storePosition)) return;

	final boolean isDuplicate = warcRecord.getWarcHeader(Name.BUBING_IS_DUPLICATE) != null;

	out.print(warcRecord.getWarcTargetURI());
	out.print('\t');
	out.print(warcRecord.getWarcHeader(Name.WARC_PAYLOAD_DIGEST).getValue());
	out.print('\t');
	out.print(isDuplicate ? -1 : finalPosition++);
	out.write('\t');
	out.print(((HttpResponseWarcRecord)warcRecord).getStatusLine());
	out.write('\n');
}
 
Example 12
Source File: URLPositionWriter.java    From BUbiNG with Apache License 2.0 5 votes vote down vote up
@Override
public void write(final WarcRecord warcRecord, final long storePosition, final PrintStream out) throws IOException {
	if (repeatedSet.contains(storeIndexMask | storePosition)) return;

	out.print(warcRecord.getWarcTargetURI());
	out.print('\t');
	out.print(storePosition);
	out.write('\n');
}
 
Example 13
Source File: URLDigestStatusLengthWriter.java    From BUbiNG with Apache License 2.0 5 votes vote down vote up
@Override
public void write(final WarcRecord warcRecord, final long storePosition, final PrintStream out) throws IOException {
	out.print(warcRecord.getWarcTargetURI());
	out.print('\t');
	out.print(warcRecord.getWarcHeader(Name.WARC_PAYLOAD_DIGEST).getValue());
	out.print('\t');
	out.print(((HttpResponseWarcRecord)warcRecord).getStatusLine().getStatusCode());
	out.print('\t');
	out.print(warcRecord.getWarcHeader(WarcHeader.Name.BUBING_IS_DUPLICATE));
	out.print('\t');
	out.print(((HttpResponseWarcRecord)warcRecord).getEntity().getContentLength());
	out.write('\n');
}
 
Example 14
Source File: TimeWindowFixedBoundaryHistogram.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Override
void outputSummary(PrintStream printStream, double bucketScaling) {
    printStream.format("%14s %10s\n\n", "Bucket", "TotalCount");

    String bucketFormatString = "%14.1f %10d\n";

    for (int i = 0; i < buckets.length; i++) {
        printStream.format(Locale.US, bucketFormatString,
                buckets[i] / bucketScaling,
                currentHistogram().values.get(i));
    }

    printStream.write('\n');
}
 
Example 15
Source File: TemplateResult.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void write(final PrintStream output) throws IOException {
    final byte[] serializedTemplate = TemplateSerializer.serialize(templateDTO);
    if (exportFileName != null) {
        try (final OutputStream resultOut = new FileOutputStream(exportFileName)) {
            resultOut.write(serializedTemplate);
        }
    } else {
        output.write(serializedTemplate);
    }
}
 
Example 16
Source File: ConstantPositionURLWriter.java    From BUbiNG with Apache License 2.0 5 votes vote down vote up
@Override
public void write(final WarcRecord warcRecord, final long storePosition, final PrintStream out) throws IOException {
	out.print(constant);
	out.print('\t');
	out.print(storePosition);
	out.write('\t');
	out.print(warcRecord.getWarcTargetURI());
	out.write('\n');
}
 
Example 17
Source File: GeoTiff.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void printBytes(PrintStream ps, String head, ByteBuffer buffer, int n) {
  ps.print(head + " == ");
  for (int i = 0; i < n; i++) {
    byte b = buffer.get();
    int ub = (b < 0) ? b + 256 : b;
    ps.print(ub + "(");
    ps.write(b);
    ps.print(") ");
  }
  ps.println();
}
 
Example 18
Source File: RequestLoggerImpl.java    From java-client-api with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <T> T copyContent(T content) {
  if (content == null)
    return content;

  long max = getContentMax();
  if (max < 1)
    return content;

  PrintStream out = getPrintStream();
  if (out == null)
    return content;

  if (content instanceof byte[]) {
    byte[] b = (byte[]) content;
    out.write(b, 0, (int) Math.min(b.length, max));
    return content;
  }

  if (content instanceof File) {
    out.println("info: cannot copy content from "+
      ((File) content).getAbsolutePath());
    return content;
  }

  if (content instanceof InputStream) {
    return (T) new InputStreamTee((InputStream) content, out, max);
  }

  if (content instanceof Reader) {
    return (T) new ReaderTee((Reader) content, out, max);
  }

  if (content instanceof String) {
    String s = (String) content;
    int len = s.length();
    if (len <= max)
      out.print(s);
    else
      out.print(s.substring(0, (int) Math.min(len, max)));
    return content;
  }

  if (logger.isWarnEnabled())
    logger.warn("Unknown {} class for content", content.getClass().getName());
  return content;
}
 
Example 19
Source File: ByteWriter.java    From BUbiNG with Apache License 2.0 4 votes vote down vote up
@Override
public void write(final byte[] b, final long storePosition, final PrintStream out) throws IOException {
	out.write(b);
}
 
Example 20
Source File: MultiPrintStream.java    From JarShrink with Apache License 2.0 3 votes vote down vote up
@Override
public void write(byte[] buffer, int off, int len) {
	
	for (PrintStream out : streams) {
		
		out.write(buffer, off, len);
	}
	
}