本文整理汇总了Java中java.io.PrintStream.write方法的典型用法代码示例。如果您正苦于以下问题:Java PrintStream.write方法的具体用法?Java PrintStream.write怎么用?Java PrintStream.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.PrintStream
的用法示例。
在下文中一共展示了PrintStream.write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: hexDigit
import java.io.PrintStream; //导入方法依赖的package包/类
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);
}
示例2: testBomUtf8
import java.io.PrintStream; //导入方法依赖的package包/类
@Test
public void testBomUtf8() throws Exception {
// Simple .csv file with a UTF-8 BOM. Should read successfully
File testFolder = tempDir.newFolder("testUtf8Folder");
File testFile = new File(testFolder, "utf8.csv");
PrintStream p = new PrintStream(testFile);
p.write(ByteOrderMark.UTF_8.getBytes(), 0, ByteOrderMark.UTF_8.length());
p.print("A,B\n");
p.print("5,7\n");
p.close();
testBuilder()
.sqlQuery(String.format("select * from table(dfs.`%s` (type => 'text', " +
"fieldDelimiter => ',', lineDelimiter => '\n', extractHeader => true))",
testFile.getAbsolutePath()))
.unOrdered()
.baselineColumns("A","B")
.baselineValues("5", "7")
.go();
}
示例3: testErrorBomUtf16
import java.io.PrintStream; //导入方法依赖的package包/类
@Test
public void testErrorBomUtf16() throws Exception {
// UTF-16 BOM should cause a dataReadError user exception
File testFolder = tempDir.newFolder("testUtf16Folder");
File testFile = new File(testFolder, "utf16.csv");
PrintStream p = new PrintStream(testFile);
p.write(ByteOrderMark.UTF_16LE.getBytes(), 0, ByteOrderMark.UTF_16LE.length());
p.print("A,B\n");
p.print("5,7\n");
p.close();
thrownException.expect(new UserExceptionMatcher(UserBitShared.DremioPBError.ErrorType.DATA_READ,
"DATA_READ ERROR: UTF-16 files not supported"));
// NB: using test() instead of testBuilder() because it unwraps the thrown RpcException and re-throws the
// underlying UserException (which is then matched with the UserExceptionMatcher)
test(String.format("select * from table(dfs.`%s` (type => 'text', " +
"fieldDelimiter => ',', lineDelimiter => '\n', extractHeader => true))",
testFile.getAbsolutePath()));
}
示例4: createOkResponse
import java.io.PrintStream; //导入方法依赖的package包/类
private void createOkResponse(PrintStream output, byte[] bytes) throws IOException {
// formatting response
output.println("HTTP/1.0 200 OK");
output.println("Content-Type: text/html");
output.println("Content-Length: " + bytes.length);
output.println();
output.write(bytes);
output.flush();
}
示例5: write
import java.io.PrintStream; //导入方法依赖的package包/类
@Override
public void write(@NonNull byte[] buf, int off, int len) {
super.write(buf, off, len);
if (streams != null) {
for (PrintStream printStream : streams) {
printStream.write(buf, off, len);
}
}
}
示例6: write
import java.io.PrintStream; //导入方法依赖的package包/类
@Override
public void write(final WarcRecord warcRecord, final long storePosition, final PrintStream out) throws IOException {
out.print(warcRecord.getWarcTargetURI());
out.write('\t');
out.print(warcRecord.getWarcHeader(Name.WARC_PAYLOAD_DIGEST).getValue());
out.write('\n');
}
示例7: readContainerLogs
import java.io.PrintStream; //导入方法依赖的package包/类
private static void readContainerLogs(DataInputStream valueStream,
PrintStream out, long logUploadedTime) throws IOException {
byte[] buf = new byte[65535];
String fileType = valueStream.readUTF();
String fileLengthStr = valueStream.readUTF();
long fileLength = Long.parseLong(fileLengthStr);
out.print("LogType:");
out.println(fileType);
if (logUploadedTime != -1) {
out.print("Log Upload Time:");
out.println(Times.format(logUploadedTime));
}
out.print("LogLength:");
out.println(fileLengthStr);
out.println("Log Contents:");
long curRead = 0;
long pendingRead = fileLength - curRead;
int toRead =
pendingRead > buf.length ? buf.length : (int) pendingRead;
int len = valueStream.read(buf, 0, toRead);
while (len != -1 && curRead < fileLength) {
out.write(buf, 0, len);
curRead += len;
pendingRead = fileLength - curRead;
toRead =
pendingRead > buf.length ? buf.length : (int) pendingRead;
len = valueStream.read(buf, 0, toRead);
}
out.println("End of LogType:" + fileType);
out.println("");
}
示例8: write
import java.io.PrintStream; //导入方法依赖的package包/类
@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');
}
示例9: write
import java.io.PrintStream; //导入方法依赖的package包/类
@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');
}
示例10: write
import java.io.PrintStream; //导入方法依赖的package包/类
@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');
}
示例11: write
import java.io.PrintStream; //导入方法依赖的package包/类
@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');
}
示例12: write
import java.io.PrintStream; //导入方法依赖的package包/类
@Override
public void write(final WarcRecord warcRecord, final long storePosition, final PrintStream out) throws IOException {
out.print(ft.format(warcRecord.getWarcDate()));
out.write('\t');
out.print(warcRecord.getWarcTargetURI());
out.write('\n');
}
示例13: write
import java.io.PrintStream; //导入方法依赖的package包/类
@Override
public void write(PrintStream out, String s) throws IOException {
try { out.write(s.getBytes("UTF-8")); }
catch (UnsupportedEncodingException uee) { uee.printStackTrace(); }
}
示例14: render
import java.io.PrintStream; //导入方法依赖的package包/类
public long render(long count, PrintStream outStream, boolean toFile) {
if (count != 0) {
int currentCount = 0;
int countPerIteration = RND_PER_REQUEST;
String[] rndArray = null;
long maxLength = -1;
long columns = -1;
long columnCounter = -1;
long lineCount = 0;
long maxLines = 0;
while (currentCount < count) {
int nextLength = currentCount + countPerIteration > count ? (int) (count - currentCount) : countPerIteration;
if (rndArray == null || nextLength != rndArray.length) {
rndArray = new String[nextLength];
}
randomGenerator.request(rndArray);
if (maxLength <= 0) {
maxLength = getMaxLength(rndArray);
columns = getColumnCount(maxLength);
columnCounter = columns;
}
if (maxLines <= 0) {
maxLines = (long) ((double) count / (double) columns);
}
for (int i = 0; i < rndArray.length; i++) {
String randomString = rndArray[i];
try {
if (columns == 1) {
outStream.write(encoderFormat.asBytes(randomString));
} else {
outStream.write(encoderFormat.asBytes(String.format("%-" + maxLength + "s", randomString)));
}
columnCounter--;
if (columnCounter == 0 && i + 1 != count) {
columnCounter = columns;
outStream.write(encoderFormat.asBytes(toFile ? encoderFormat.newLineFile() : encoderFormat.newLineCmdLine()));
lineCount++;
if (lineCount % LINE_BREAK_EVERY_LINES == 0 && (maxLines - lineCount > LINE_BREAK_EVERY_LINES / 2)) {
outStream.write(encoderFormat.asBytes(toFile ? encoderFormat.paragraphFile() : encoderFormat.paragraphCmdLine()));
}
} else {
outStream.write(encoderFormat.asBytes(toFile ? encoderFormat.separatorFile() : encoderFormat.separatorFile()));
}
} catch (Exception e) {
throw new IllegalStateException("could not write random to output stream", e);
}
}
currentCount += rndArray.length;
}
}
return count;
}
示例15: write
import java.io.PrintStream; //导入方法依赖的package包/类
@Override
public void write(final Object processedRecord, final long storePosition, final PrintStream out) throws IOException {
out.write(processedRecord.toString().getBytes(Charsets.UTF_8));
out.write('\n');
}