當前位置: 首頁>>代碼示例>>Java>>正文


Java BufferedInputStream.skip方法代碼示例

本文整理匯總了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());
    }
}
 
開發者ID:aws,項目名稱:aws-sdk-java-v2,代碼行數:21,代碼來源:BufferedInputStreamResetTest.java

示例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;
}
 
開發者ID:TheDudeFromCI,項目名稱:Project-Sarica-v3,代碼行數:17,代碼來源:HandwrittenDigitBase.java

示例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);
}
 
開發者ID:aws,項目名稱:aws-sdk-java-v2,代碼行數:17,代碼來源:BufferedInputStreamResetTest.java

示例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());
    }
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:20,代碼來源:BufferedInputStreamResetTest.java

示例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;
}
 
開發者ID:TheDudeFromCI,項目名稱:Project-Sarica-v3,代碼行數:15,代碼來源:HandwrittenDigitBase.java

示例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;
	}
}
 
開發者ID:starn,項目名稱:encdroidMC,代碼行數:13,代碼來源:FileProvider6.java

示例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;
}
 
開發者ID:starn,項目名稱:encdroidMC,代碼行數:9,代碼來源:FileProvider3.java

示例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);
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:16,代碼來源:BufferedInputStreamResetTest.java

示例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;
}
 
開發者ID:bsteker,項目名稱:bdf2,代碼行數:47,代碼來源:ProcessDownloadController.java


注:本文中的java.io.BufferedInputStream.skip方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。