本文整理汇总了Java中java.io.OutputStream.flush方法的典型用法代码示例。如果您正苦于以下问题:Java OutputStream.flush方法的具体用法?Java OutputStream.flush怎么用?Java OutputStream.flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.OutputStream
的用法示例。
在下文中一共展示了OutputStream.flush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doGet
import java.io.OutputStream; //导入方法依赖的package包/类
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String idStr = request.getParameter("id");
if (idStr != null) {
Long id = Long.valueOf(idStr);
LocationPicture picture = null;
if (id >= 0) {
picture = LocationPictureDAO.getInstance().get(id);
} else {
Map<Long, LocationPicture> temp = (Map<Long, LocationPicture>)request.getSession().getAttribute(TEMP_ROOM_PICTURES);
if (temp != null)
picture = temp.get(id);
}
if (picture != null) {
response.setContentType(picture.getContentType());
response.setHeader( "Content-Disposition", "attachment; filename=\"" + picture.getFileName() + "\"" );
OutputStream out = response.getOutputStream();
out.write(picture.getDataFile());
out.flush();
} else {
new ServletException("Room picture of the given id does not exist.");
}
}
new ServletException("No room picture id provided.");
}
示例2: api
import java.io.OutputStream; //导入方法依赖的package包/类
@RequestMapping(AdminBiz.MAPPING)
@PermessionLimit(limit=false)
public void api(HttpServletRequest request, HttpServletResponse response) throws IOException {
// invoke
RpcResponse rpcResponse = doInvoke(request);
// serialize response
byte[] responseBytes = HessianSerializer.serialize(rpcResponse);
response.setContentType("text/html;charset=utf-8");
response.setStatus(HttpServletResponse.SC_OK);
//baseRequest.setHandled(true);
OutputStream out = response.getOutputStream();
out.write(responseBytes);
out.flush();
}
示例3: testOverwriteFile
import java.io.OutputStream; //导入方法依赖的package包/类
/**
* Test case where there is no existing file
*/
@Test
public void testOverwriteFile() throws IOException {
assertTrue("Creating empty dst file", DST_FILE.createNewFile());
OutputStream fos = new AtomicFileOutputStream(DST_FILE);
assertTrue("Empty file still exists", DST_FILE.exists());
fos.write(TEST_STRING.getBytes());
fos.flush();
// Original contents still in place
assertEquals("", DFSTestUtil.readFile(DST_FILE));
fos.close();
// New contents replace original file
String readBackData = DFSTestUtil.readFile(DST_FILE);
assertEquals(TEST_STRING, readBackData);
}
示例4: fullyBufferedPostIsTooLong
import java.io.OutputStream; //导入方法依赖的package包/类
@Test public void fullyBufferedPostIsTooLong() throws Exception {
server.enqueue(new MockResponse().setBody("A"));
connection = urlFactory.open(server.url("/b").url());
connection.setRequestProperty("Content-Length", "3");
connection.setRequestMethod("POST");
OutputStream out = connection.getOutputStream();
out.write('a');
out.write('b');
out.write('c');
try {
out.write('d');
out.flush();
fail();
} catch (IOException expected) {
}
}
示例5: a
import java.io.OutputStream; //导入方法依赖的package包/类
protected static final String a(Bitmap bitmap, String str, String str2) {
File file = new File(str);
if (!file.exists()) {
file.mkdirs();
}
String stringBuffer = new StringBuffer(str).append(str2).toString();
File file2 = new File(stringBuffer);
if (file2.exists()) {
file2.delete();
}
if (bitmap != null) {
try {
OutputStream fileOutputStream = new FileOutputStream(file2);
bitmap.compress(CompressFormat.JPEG, 80, fileOutputStream);
fileOutputStream.flush();
fileOutputStream.close();
bitmap.recycle();
return stringBuffer;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e2) {
e2.printStackTrace();
}
}
return null;
}
示例6: writeTo
import java.io.OutputStream; //导入方法依赖的package包/类
public void writeTo(OutputStream out) throws IOException {
out.write(this.header);
SimpleMultipartEntity.this.updateProgress((long) this.header.length);
FileInputStream inputStream = new FileInputStream(this.file);
byte[] tmp = new byte[4096];
while (true) {
int bytesRead = inputStream.read(tmp);
if (bytesRead != -1) {
out.write(tmp, 0, bytesRead);
SimpleMultipartEntity.this.updateProgress((long) bytesRead);
} else {
out.write(SimpleMultipartEntity.CR_LF);
SimpleMultipartEntity.this.updateProgress((long) SimpleMultipartEntity.CR_LF
.length);
out.flush();
AsyncHttpClient.silentCloseInputStream(inputStream);
return;
}
}
}
示例7: bytesToStorage
import java.io.OutputStream; //导入方法依赖的package包/类
private void bytesToStorage(byte[] data) {
OutputStream outputStream = null;
try {
outputStream = storage.write();
outputStream.write(data);
outputStream.flush();
} catch (IOException ignored) {
} finally {
safeClose(outputStream);
}
}
示例8: readFile
import java.io.OutputStream; //导入方法依赖的package包/类
@Override
public ResponseEntity<StreamingResponseBody> readFile(String fileLocation, String imageDir, String id,
String fileName) {
StreamingResponseBody streamingResponseBody = new StreamingResponseBody() {
@Override
public void writeTo(OutputStream outputStream) {
try {
String fileStr = fileLocation + File.separator + imageDir + File.separator + id + File.separator
+ fileName;
RandomAccessFile file = new RandomAccessFile(fileStr, "r");
FileChannel inChannel = file.getChannel();
ByteBuffer buffer = ByteBuffer.allocate(1024);
while (inChannel.read(buffer) > 0) {
buffer.flip();
for (int i = 0; i < buffer.limit(); i++) {
outputStream.write(buffer.get());
}
buffer.clear();
outputStream.flush();
}
inChannel.close();
file.close();
} catch (IOException e) {
logger.error("Image Not Found : error " + e.getMessage());
throw new ResourceNotFoundException("Image Not Found : " + id + "/" + fileName);
}
}
};
HttpHeaders headers = new HttpHeaders();
headers.add(HttpHeaders.CONTENT_TYPE, "image/*");
return new ResponseEntity<StreamingResponseBody>(streamingResponseBody, headers, HttpStatus.OK);
}
示例9: deployProcessToServer
import java.io.OutputStream; //导入方法依赖的package包/类
private Throwable deployProcessToServer() {
Throwable throwable = null;
try {
HttpURLConnection conn = this.buildHttpURLConnection();
StringBuffer sb = new StringBuffer();
sb.append("--");
sb.append(BOUNDARY);
sb.append("\r\n");
sb.append("Content-Disposition: form-data; name=\"processzipfile\"; filename=\"processzipfile.zip\"\r\n");
sb.append("Content-Type:application/x-zip-compressed\r\n\r\n");
byte[] data = sb.toString().getBytes();
byte[] end_data = ("\r\n--" + BOUNDARY + "--\r\n").getBytes();
OutputStream os = conn.getOutputStream();
os.write(data);
String tempProcessZipFile=this.buildTempDeploymentZipFile();
FileInputStream fis=new FileInputStream(tempProcessZipFile);
int rn2;
byte[] buf2 = new byte[1024];
while((rn2=fis.read(buf2, 0, 1024))>0){
os.write(buf2,0,rn2);
}
os.write(end_data);
os.flush();
os.close();
fis.close();
InputStream is = conn.getInputStream();
byte[] inbuf = new byte[1024];
int rn;
while((rn=is.read(inbuf,0,1024))>0){
System.out.write(inbuf,0,rn);
}
is.close();
File file=new File(tempProcessZipFile);
if(file.exists())file.delete();
} catch (Exception e) {
throwable = e;
}
return throwable;
}
示例10: exportData
import java.io.OutputStream; //导入方法依赖的package包/类
/**
* 导出数据
* @param builder
* @param labelsSupplier
* @param contentSupplier
* @param out 经过分词器的输出流
*/
protected void exportData(QueryBuilder builder, Function<SearchResponse, List<List<String>>> labelsSupplier,
Function<SearchResponse, List<String>> contentSupplier, OutputStream out) {
final int size = 50;
String scrollId = null;
int page = 1;
while(true) {
LOG.debug("正在输出第" + page + "页,query:" + builder);
SearchResponse response;
if(StringUtils.isBlank(scrollId)) {
response = search().setQuery(builder).setSize(size)
.setScroll(SCROLL_TIMEOUT).get();
scrollId = response.getScrollId();
} else {
response = client.prepareSearchScroll(scrollId)
.setScroll(SCROLL_TIMEOUT).get();
}
final List<List<String>> labels = labelsSupplier.apply(response);
final List<String> contentList = contentSupplier.apply(response);
Preconditions.checkNotNull(labels);
Preconditions.checkNotNull(contentList);
if(contentList.size()<=0)
break;
//开始分词
List<String> combine;
if(labels.size() > 0) {
combine = labels.stream().map(list -> list.parallelStream().collect(Collectors.joining("/")))
.collect(Collectors.toList());
for(int i = 0;i<labels.size();i++)
combine.set(i, combine.get(i) + " " + contentList.get(i));
} else
combine = contentList;
page++;
try {
IOUtils.write(combine.stream().collect(Collectors.joining("\n")) + "\n", out, "utf-8");
out.flush();
} catch(IOException e) {
LOG.error("文件写出错误, 由于 " + e.getLocalizedMessage());
}
}
}
示例11: a
import java.io.OutputStream; //导入方法依赖的package包/类
private void a(Context context, String str, String str2, String str3, Bitmap bitmap, int i, k kVar) {
IMediaObject wXVideoObject = new WXVideoObject();
wXVideoObject.videoUrl = str3;
WXMediaMessage wXMediaMessage = new WXMediaMessage();
wXMediaMessage.title = str;
wXMediaMessage.description = str2;
wXMediaMessage.mediaObject = wXVideoObject;
OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.PNG, 100, byteArrayOutputStream);
byteArrayOutputStream.flush();
byteArrayOutputStream.close();
wXMediaMessage.thumbData = a(context, byteArrayOutputStream.toByteArray());
a(wXMediaMessage, "video", i, kVar);
}
示例12: copyDataBase
import java.io.OutputStream; //导入方法依赖的package包/类
private void copyDataBase() throws IOException
{
InputStream mInput = mContext.getAssets().open(DB_NAME_ELEMENTS);
String outFileName = DB_PATH + DB_NAME_ELEMENTS;
OutputStream mOutput = new FileOutputStream(outFileName);
byte[] mBuffer = new byte[1024];
int mLength;
while ((mLength = mInput.read(mBuffer))>0)
{
mOutput.write(mBuffer, 0, mLength);
}
mOutput.flush();
mOutput.close();
mInput.close();
}
示例13: write
import java.io.OutputStream; //导入方法依赖的package包/类
private static void write(
OutputStream out, byte[] b, int off, int len, boolean singleByte)
throws IOException {
if (singleByte) {
for (int i = off; i < off + len; i++) {
out.write(b[i]);
}
} else {
out.write(b, off, len);
}
out.flush(); // for coverage
}
示例14: copy
import java.io.OutputStream; //导入方法依赖的package包/类
/**
* @param inputStream
* @param outputStream
* @param bufferSize
* @throws IOException
*/
public static void copy(InputStream inputStream, OutputStream outputStream, int bufferSize) throws IOException {
int length = 0;
byte[] buffer = new byte[bufferSize];
while((length = inputStream.read(buffer, 0, bufferSize)) > -1) {
outputStream.write(buffer, 0, length);
}
outputStream.flush();
}
示例15: writeTo
import java.io.OutputStream; //导入方法依赖的package包/类
public void writeTo(final OutputStream outstream) throws IOException {
Args.notNull(outstream, "Output stream");
if (this.objSer == null) {
final ObjectOutputStream out = new ObjectOutputStream(outstream);
out.writeObject(this.objRef);
out.flush();
} else {
outstream.write(this.objSer);
outstream.flush();
}
}