当前位置: 首页>>代码示例>>Java>>正文


Java BufferedInputStream.read方法代码示例

本文整理汇总了Java中java.io.BufferedInputStream.read方法的典型用法代码示例。如果您正苦于以下问题:Java BufferedInputStream.read方法的具体用法?Java BufferedInputStream.read怎么用?Java BufferedInputStream.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.io.BufferedInputStream的用法示例。


在下文中一共展示了BufferedInputStream.read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: downloadUrlToStream

import java.io.BufferedInputStream; //导入方法依赖的package包/类
/**
 * Download a bitmap from a URL and write the content to an output stream.
 *
 * @param urlString The URL to fetch
 * @return true if successful, false otherwise
 */
private boolean downloadUrlToStream(String urlString, OutputStream outputStream) throws IOException{
    final URL url = new URL(urlString);
    HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
    BufferedInputStream in = new BufferedInputStream(urlConnection.getInputStream(), IO_BUFFER_SIZE);
    BufferedOutputStream out = new BufferedOutputStream(outputStream, IO_BUFFER_SIZE);

    int b;
    while ((b = in.read()) != -1) {
        out.write(b);
    }

    urlConnection.disconnect();

    try {
        out.close();
        in.close();
    } catch (final IOException e) {e.printStackTrace();}

    return true;
}
 
开发者ID:EvilBT,项目名称:HDImageView,代码行数:27,代码来源:NetworkInterceptor.java

示例2: check

import java.io.BufferedInputStream; //导入方法依赖的package包/类
private void check(File file, List<CheckFailure> errors, Mode mode) throws IOException {
	BufferedInputStream is = new BufferedInputStream(new FileInputStream(file));
	try {
		int line = 1;
		int prev = -1;
		int ch;
		while ((ch = is.read()) != -1) {
			if (ch == '\n') {
				if (mode == Mode.LF && prev == '\r') {
					errors.add(new CheckFailure(file, line, "CRLF"));
					return;
				} else if (mode == Mode.CRLF && prev != '\r') {
					errors.add(new CheckFailure(file, line, "LF"));
					return;
				}
				line++;
			} else if (prev == '\r') {
				errors.add(new CheckFailure(file, line, "CR"));
				return;
			}
			prev = ch;
		}
	} finally {
		is.close();
	}
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:27,代码来源:CheckEol.java

示例3: readkey

import java.io.BufferedInputStream; //导入方法依赖的package包/类
/** Helper method that read "key =" then return the key part (with leading and trailing spaces removed).
 * This method can only be called after you've synchronized on SimInstance's class.
 */
private static String readkey(BufferedInputStream bis) throws IOException {
    int n = 0;
    while(true) {
        int c = bis.read();
        if (c<0) return "";
        if (c=='=') break;
        if (readcache==null) readcache = new byte[64]; // to ensure proper detection of out-of-memory error, this number must be 2^n for some n>=0
        while(n >= readcache.length) {
           byte[] readcache2 = new byte[readcache.length * 2];
           System.arraycopy(readcache, 0, readcache2, 0, readcache.length);
           readcache = readcache2;
        }
        readcache[n] = (byte)c;
        n++;
    }
    while(n>0 && readcache[n-1]>0 && readcache[n-1]<=' ') n--; // skip trailing spaces
    int i = 0;
    while(i<n && readcache[i]>0 && readcache[i]<=' ') i++; // skip leading space
    return new String(readcache, i, n-i, "UTF-8");
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:24,代码来源:SimInstance.java

示例4: zipSingleFile

import java.io.BufferedInputStream; //导入方法依赖的package包/类
/**
 * Compress a single file
 *  
 * @param file file
 * @param out  file stream
 * @param baseDir  The relative address of the file
 */
private static void zipSingleFile(File file, ZipOutputStream out,String baseDir) {  
	if (!file.exists()) {  
		return;  
	}  
	try {  
		int buffer = FILE_BUFFER_SIZE;
		BufferedInputStream bis = new BufferedInputStream(  
				new FileInputStream(file));  
		ZipEntry entry = new ZipEntry(baseDir + file.getName());  
		out.putNextEntry(entry);  
		int count;  
		byte data[] = new byte[buffer];  
		while ((count = bis.read(data, 0, buffer)) != -1) {  
			out.write(data, 0, count);  
		}  
		bis.close();  
	} catch (Exception e) {  
		throw new RuntimeException(e);  
	}  
}
 
开发者ID:ICT-BDA,项目名称:EasyML,代码行数:28,代码来源:FileDownloadServlet.java

示例5: makeClassLoaderTestJar

import java.io.BufferedInputStream; //导入方法依赖的package包/类
private File makeClassLoaderTestJar(String... clsNames) throws IOException {
  File jarFile = new File(TEST_ROOT_DIR, TEST_JAR_2_NAME);
  JarOutputStream jstream =
      new JarOutputStream(new FileOutputStream(jarFile));
  for (String clsName: clsNames) {
    String name = clsName.replace('.', '/') + ".class";
    InputStream entryInputStream = this.getClass().getResourceAsStream(
        "/" + name);
    ZipEntry entry = new ZipEntry(name);
    jstream.putNextEntry(entry);
    BufferedInputStream bufInputStream = new BufferedInputStream(
        entryInputStream, 2048);
    int count;
    byte[] data = new byte[2048];
    while ((count = bufInputStream.read(data, 0, 2048)) != -1) {
      jstream.write(data, 0, count);
    }
    jstream.closeEntry();
  }
  jstream.close();

  return jarFile;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:24,代码来源:TestRunJar.java

示例6: readBytes

import java.io.BufferedInputStream; //导入方法依赖的package包/类
private static byte[] readBytes(File file) throws IOException {
  int byteCount = (int) file.length();

  byte[] input = new byte[byteCount];

  URL url = file.toURL();
  assertThat(url).isNotNull();

  InputStream is = url.openStream();
  assertThat(is).isNotNull();

  BufferedInputStream bis = new BufferedInputStream(is);
  int bytesRead = bis.read(input);
  bis.close();

  assertThat(bytesRead).isEqualTo(byteCount);
  return input;
}
 
开发者ID:ampool,项目名称:monarch,代码行数:19,代码来源:StatUtils.java

示例7: copyFile2

import java.io.BufferedInputStream; //导入方法依赖的package包/类
/**
 * 复制文件
 */
public static void copyFile2(File sourceFile, File targetFile)
        throws IOException {
    // 新建文件输入流并对它进行缓冲
    FileInputStream input = new FileInputStream(sourceFile);
    BufferedInputStream inBuff = new BufferedInputStream(input);

    // 新建文件输出流并对它进行缓冲
    FileOutputStream output = new FileOutputStream(targetFile);
    BufferedOutputStream outBuff = new BufferedOutputStream(output);

    // 缓冲数组
    byte[] b = new byte[1024 * 5];
    int len;
    while ((len = inBuff.read(b)) != -1) {
        outBuff.write(b, 0, len);
    }
    // 刷新此缓冲的输出流
    outBuff.flush();

    //关闭流
    inBuff.close();
    outBuff.close();
    output.close();
    input.close();
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:29,代码来源:CmdUtil.java

示例8: read

import java.io.BufferedInputStream; //导入方法依赖的package包/类
/** Read a "..." atom assuming the leading " has already been consumed. */
static SimAtom read(BufferedInputStream in) throws IOException {
    byte temp[] = new byte[64]; // to ensure proper detection of out-of-memory error, this number must be 2^n for some n>=0
    int n = 0;
    while(true) {
       int c = in.read();
       if (c<0) throw new IOException("Unexpected EOF");
       if (c=='\"') break;
       if (c=='\\') {
          c=in.read();
          if (c<0) throw new IOException("Unexpected EOF");
          if (c=='n') c='\n';
       }
       while (n >= temp.length) {
          byte temp2[] = new byte[temp.length * 2];
          System.arraycopy(temp, 0, temp2, 0, temp.length);
          temp = temp2;
       }
       temp[n]=(byte)c;
       n++;
    }
    return make(new String(temp, 0, n, "UTF-8"));
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:24,代码来源:SimAtom.java

示例9: checkBlob

import java.io.BufferedInputStream; //导入方法依赖的package包/类
private boolean checkBlob(byte[] retrBytes) throws Exception {
    boolean passed = false;
    BufferedInputStream bIn = new BufferedInputStream(new FileInputStream(testBlobFile));

    try {
        int fileLength = (int) testBlobFile.length();
        if (retrBytes.length == fileLength) {
            for (int i = 0; i < fileLength; i++) {
                byte fromFile = (byte) (bIn.read() & 0xff);

                if (retrBytes[i] != fromFile) {
                    passed = false;
                    System.out.println("Byte pattern differed at position " + i + " , " + retrBytes[i] + " != " + fromFile);

                    for (int j = 0; (j < (i + 10)) /* && (j < i) */; j++) {
                        System.out.print(Integer.toHexString(retrBytes[j] & 0xff) + " ");
                    }

                    break;
                }

                passed = true;
            }
        } else {
            passed = false;
            System.out.println("retrBytes.length(" + retrBytes.length + ") != testBlob.length(" + fileLength + ")");
        }

        return passed;
    } finally {
        if (bIn != null) {
            bIn.close();
        }
    }
}
 
开发者ID:rafallis,项目名称:BibliotecaPS,代码行数:36,代码来源:BlobTest.java

示例10: readMagic

import java.io.BufferedInputStream; //导入方法依赖的package包/类
static byte[] readMagic(BufferedInputStream in) throws IOException {
    in.mark(4);
    byte[] magic = new byte[4];
    for (int i = 0; i < magic.length; i++) {
        // read 1 byte at a time, so we always get 4
        if (1 != in.read(magic, i, 1))
            break;
    }
    in.reset();
    return magic;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:12,代码来源:Utils.java

示例11: isReadable

import java.io.BufferedInputStream; //导入方法依赖的package包/类
/**
 * Returns true if we are confident that we can read data from this
 * connection. This is more expensive and more accurate than {@link
 * #isAlive()}; callers should check {@link #isAlive()} first.
 */
public boolean isReadable() {
  if (!(in instanceof BufferedInputStream)) {
    return true; // Optimistic.
  }
  if (isSpdy()) {
    return true; // Optimistic. We can't test SPDY because its streams are in use.
  }
  BufferedInputStream bufferedInputStream = (BufferedInputStream) in;
  try {
    int readTimeout = socket.getSoTimeout();
    try {
      socket.setSoTimeout(1);
      bufferedInputStream.mark(1);
      if (bufferedInputStream.read() == -1) {
        return false; // Stream is exhausted; socket is closed.
      }
      bufferedInputStream.reset();
      return true;
    } finally {
      socket.setSoTimeout(readTimeout);
    }
  } catch (SocketTimeoutException ignored) {
    return true; // Read timed out; socket is good.
  } catch (IOException e) {
    return false; // Couldn't read; socket is closed.
  }
}
 
开发者ID:aabognah,项目名称:LoRaWAN-Smart-Parking,代码行数:33,代码来源:Connection.java

示例12: check

import java.io.BufferedInputStream; //导入方法依赖的package包/类
private void check(File file, List<CheckFailure> errors, Mode mode)
        throws IOException {
    BufferedInputStream is = new BufferedInputStream(new FileInputStream(
            file));
    try {
        int line = 1;
        int prev = -1;
        int ch;
        while ((ch = is.read()) != -1) {
            if (ch == '\n') {
                if (mode == Mode.LF && prev == '\r') {
                    errors.add(new CheckFailure(file, line, "CRLF"));
                    return;
                } else if (mode == Mode.CRLF && prev != '\r') {
                    errors.add(new CheckFailure(file, line, "LF"));
                    return;
                }
                line++;
            } else if (prev == '\r') {
                errors.add(new CheckFailure(file, line, "CR"));
                return;
            }
            prev = ch;
        }
    } finally {
        is.close();
    }
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:29,代码来源:CheckEol.java

示例13: copytree

import java.io.BufferedInputStream; //导入方法依赖的package包/类
static void copytree(File from, File to) throws IOException {
    if (from.isDirectory()) {
        if (!to.mkdirs()) {
            throw new IOException("mkdir: " + to);
        }
        for (File f : from.listFiles()) {
            copytree(f, new File(to, f.getName()));
        }
    } else {
        InputStream is = new FileInputStream(from);
        try {
            OutputStream os = new FileOutputStream(to);
            try {
                // XXX using FileChannel would be more efficient, but more complicated
                BufferedInputStream bis = new BufferedInputStream(is);
                BufferedOutputStream bos = new BufferedOutputStream(os);
                int c;
                while ((c = bis.read()) != -1) {
                    bos.write(c);
                }
                bos.flush();
                bos.close();
            } finally {
                os.close();
            }
        } finally {
            is.close();
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:31,代码来源:NbTestCase.java

示例14: readResource

import java.io.BufferedInputStream; //导入方法依赖的package包/类
private byte[] readResource(String className, String suffix) throws IOException {
    // Note to the unwary -- "/" works on Windows, leave it alone.
    String fileName = className.replace('.', '/') + "." + suffix;
    InputStream origStream = getResourceAsStream(fileName);
    if (origStream == null) {
        throw new IOException("Resource not found : " + fileName);
    }
    BufferedInputStream stream = new java.io.BufferedInputStream(origStream);
    byte[] data = new byte[stream.available()];
    int how_many = stream.read(data);
    // Really ought to deal with the corner cases of stream.available()
    return data;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:14,代码来源:BogoLoader.java

示例15: setClasses

import java.io.BufferedInputStream; //导入方法依赖的package包/类
protected void setClasses(String jarPath) throws Exception {
    ArrayList<String> names = new ArrayList(16);
    ArrayList<byte[]> bytes = new ArrayList(16);
    JarFile file = new JarFile(jarPath);
    Enumeration<JarEntry> entries = file.entries();
    ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);
    int read = 0;
    byte[] buffer = new byte[1024];

    while (entries.hasMoreElements()) {
        JarEntry entry = entries.nextElement();

        if (entry.getName().endsWith(".class")) {
            String nm = entry.getName();
            nm = nm.substring(0, nm.lastIndexOf("."));
            names.add(nm);

            BufferedInputStream bis = new BufferedInputStream(file.getInputStream(entry));

            while ((read = bis.read(buffer)) > -1) {
                bos.write(buffer, 0, read);
            }

            bis.close();
            bytes.add(bos.toByteArray());
            bos.reset();
        }
    }

    classNames = names.toArray(new String[0]);
    classesBytes = bytes.toArray(new byte[0][]);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:33,代码来源:InstrumentationTest.java


注:本文中的java.io.BufferedInputStream.read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。