当前位置: 首页>>代码示例>>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;未经允许,请勿转载。