本文整理匯總了Java中java.io.BufferedInputStream.skip方法的典型用法代碼示例。如果您正苦於以下問題:Java BufferedInputStream.skip方法的具體用法?Java BufferedInputStream.skip怎麽用?Java BufferedInputStream.skip使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.io.BufferedInputStream
的用法示例。
在下文中一共展示了BufferedInputStream.skip方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testNegative
import java.io.BufferedInputStream; //導入方法依賴的package包/類
private void testNegative(final int readLimit) throws IOException {
byte[] bytes = new byte[100];
for (int i = 0; i < bytes.length; i++) {
bytes[i] = (byte) i;
}
// buffer of 10 bytes
BufferedInputStream bis =
new BufferedInputStream(new ByteArrayInputStream(bytes), 10);
// skip 10 bytes
bis.skip(10);
bis.mark(readLimit); // 1 byte short in buffer size
// read 30 bytes in total, with internal buffer incread to 20
bis.read(new byte[20]);
try {
bis.reset();
fail();
} catch (IOException ex) {
assertEquals("Resetting to invalid mark", ex.getMessage());
}
}
示例2: loadDigitImages
import java.io.BufferedInputStream; //導入方法依賴的package包/類
private static float[][] loadDigitImages(File file) throws Exception
{
BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));
in.skip(4);
int imageCount = nextInt(in);
float[][] images = new float[imageCount][28 * 28];
in.skip(8);
for (int i = 0; i < imageCount; i++)
for (int p = 0; p < 28 * 28; p++)
images[i][p] = in.read() / 255f;
in.close();
return images;
}
示例3: testPositive
import java.io.BufferedInputStream; //導入方法依賴的package包/類
private void testPositive(final int readLimit) throws IOException {
byte[] bytes = new byte[100];
for (int i = 0; i < bytes.length; i++) {
bytes[i] = (byte) i;
}
// buffer of 10 bytes
BufferedInputStream bis =
new BufferedInputStream(new ByteArrayInputStream(bytes), 10);
// skip 10 bytes
bis.skip(10);
bis.mark(readLimit); // buffer size would increase up to readLimit
// read 30 bytes in total, with internal buffer increased to 20
bis.read(new byte[20]);
bis.reset();
assert (bis.read() == 10);
}
示例4: testNegative
import java.io.BufferedInputStream; //導入方法依賴的package包/類
private void testNegative(final int readLimit) throws IOException {
byte[] bytes = new byte[100];
for (int i=0; i < bytes.length; i++)
bytes[i] = (byte)i;
// buffer of 10 bytes
BufferedInputStream bis =
new BufferedInputStream(new ByteArrayInputStream(bytes), 10);
// skip 10 bytes
bis.skip(10);
bis.mark(readLimit); // 1 byte short in buffer size
// read 30 bytes in total, with internal buffer incread to 20
bis.read(new byte[20]);
try {
bis.reset();
fail();
} catch(IOException ex) {
assertEquals("Resetting to invalid mark", ex.getMessage());
}
}
示例5: loadDigitLabels
import java.io.BufferedInputStream; //導入方法依賴的package包/類
private static byte[] loadDigitLabels(File file) throws Exception
{
BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));
in.skip(4);
int count = nextInt(in);
byte[] labels = new byte[count];
for (int i = 0; i < count; i++)
labels[i] = (byte)in.read();
in.close();
return labels;
}
示例6: fsDownload
import java.io.BufferedInputStream; //導入方法依賴的package包/類
@Override
public InputStream fsDownload(String path, long startIndex) throws IOException {
System.out.println("download file "+path);
try {
BufferedInputStream is = new BufferedInputStream(getNewSession().get(getAbsolutePath(path)));
if (startIndex>0) is.skip(startIndex);
return is;
} catch (SftpException e){
e.printStackTrace();
return null;
}
}
示例7: fsDownload
import java.io.BufferedInputStream; //導入方法依賴的package包/類
@Override
public InputStream fsDownload(String path, long startIndex) throws IOException {
SmbFile currentFolder = new SmbFile(getAbsolutePath(path), authentication);
//InputStream is = currentFolder.getInputStream();
BufferedInputStream is = new BufferedInputStream(new SmbFileInputStream(currentFolder));
if (startIndex>0) is.skip(startIndex);
return is;
}
示例8: testPositive
import java.io.BufferedInputStream; //導入方法依賴的package包/類
private void testPositive(final int readLimit) throws IOException {
byte[] bytes = new byte[100];
for (int i=0; i < bytes.length; i++)
bytes[i] = (byte)i;
// buffer of 10 bytes
BufferedInputStream bis =
new BufferedInputStream(new ByteArrayInputStream(bytes), 10);
// skip 10 bytes
bis.skip(10);
bis.mark(readLimit); // buffer size would increase up to readLimit
// read 30 bytes in total, with internal buffer increased to 20
bis.read(new byte[20]);
bis.reset();
assert(bis.read() == 10);
}
示例9: doHandleRequest
import java.io.BufferedInputStream; //導入方法依賴的package包/類
@Override
protected ModelAndView doHandleRequest(HttpServletRequest req,HttpServletResponse res) throws Exception {
String id = req.getParameter(ID_KEY);
if (!StringUtils.hasText(id)) {
id = (String) req.getAttribute(ID_KEY);
}
if(StringUtils.isEmpty(id)){
throw new RuntimeException("Upload definition id can not be null!");
}
UploadDefinition uploadDef=fileService.getUploadDefinition(id);
if(StringUtils.isEmpty(uploadDef.getUploadProcessorKey())){
throw new RuntimeException("Upload definition ["+id+"] has not set processor!");
}
String fileName = uploadDef.getFileName();
fileName = new String(fileName.getBytes("GBK"), "ISO8859-1");
res.setContentType("application/octet-stream");
res.setHeader("Connection", "close");// 表示不能用瀏覽器直接打開
res.setHeader("Accept-Ranges", "bytes");// 告訴客戶端允許斷點續傳多線程連接下載
long p = 0;
if (req.getHeader("Range") != null) {// 客戶端請求的下載的文件塊的開始字節
res.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
p = Long.parseLong(req.getHeader("Range").replaceAll("bytes=", "").replaceAll("-", ""));
}
res.setHeader("Content-Disposition", "attachment;filename=\"" + fileName + "\"");
InputStream in = fileService.getFile(uploadDef);
BufferedInputStream bin = new BufferedInputStream(in);
bin.skip(p);
long fileTotalLong = uploadDef.getSize();
// 下載的文件(或塊)長度響應的格式是Content-Length: [文件的總大小] - [客戶端請求的下載的文件塊的開始字節]
res.setHeader("Content-Length", new Long(fileTotalLong - p).toString());
if (p != 0) {
// 如果不是從最開始下載,那麽設置響應格式Content-Range: bytes [文件塊的開始字節]-[文件的總大小
// -1]/[文件的總大小]
res.setHeader("Content-Range", "bytes " + new Long(p).toString() + "-"
+ (fileTotalLong - 1) + "/" + fileTotalLong);
}
ServletOutputStream out = res.getOutputStream();
try {
IOUtils.copy(bin, out);
} finally {
IOUtils.closeQuietly(in);
}
out.flush();
out.close();
return null;
}