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


Java BufferedInputStream类代码示例

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


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

示例1: testProtocolThrottling

import java.io.BufferedInputStream; //导入依赖的package包/类
/**
 * This verifies that the PseudoServer can be restricted to a HTTP/1.0.
 */
public void testProtocolThrottling() throws Exception {
    getServer().setMaxProtocolLevel( 1, 0 );
    defineResource( "sample", "Get this", "text/plain" );
    Socket socket = new Socket( "localhost", getHostPort() );
    OutputStream os = socket.getOutputStream();
    InputStream is = new BufferedInputStream( socket.getInputStream() );

    sendHTTPLine( os, "GET /sample HTTP/1.1" );
    sendHTTPLine( os, "Host: meterware.com" );
    sendHTTPLine( os, "Connection: close" );
    sendHTTPLine( os, "" );

    StringBuffer sb = new StringBuffer();
    int b;
    while (-1 != (b = is.read())) sb.append( (char) b );
    String result = sb.toString();
    assertTrue( "Did not find matching protocol", result.startsWith( "HTTP/1.0" ) );
    assertTrue( "Did not find expected text", result.indexOf( "Get this" ) > 0 );
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:23,代码来源:PseudoServerTest.java

示例2: run

import java.io.BufferedInputStream; //导入依赖的package包/类
/**
 * The sound is load and play in a thread no slow down the engine.
 * */
@Override
public void run() {
    try {
        InputStream in = new BufferedInputStream(this.getClass().getResourceAsStream(this.filename + ".wav"));
        Clip clip = AudioSystem.getClip();

        clip.open(AudioSystem.getAudioInputStream(in));
        if (this.loop){
            clip.loop(Clip.LOOP_CONTINUOUSLY);
        }
        clip.start();
    }catch (Exception e){
        System.err.println(e);
    }

}
 
开发者ID:Exia-Aix-A2,项目名称:Boulder-Dash,代码行数:20,代码来源:Sound.java

示例3: uploadFile

import java.io.BufferedInputStream; //导入依赖的package包/类
public boolean uploadFile(File file, byte[] value) {
	boolean result = false;
	if (null == value) {
		return result;
	}
	FTPClient ftpClient = ftpConnManager.getFTPClient();
	if (null == ftpClient || !ftpClient.isConnected()) {
		return result;
	}
	try (BufferedInputStream in = new BufferedInputStream(new ByteArrayInputStream(value))) {
		boolean storeFile = ftpClient.storeFile(file.getName(), in);
		if (storeFile) {
			result = true;
			log.info("file-->" + file.getPath() + "成功上传至FTP服务器");
		}
	} catch (Exception e) {
		log.error("error", e);
	} finally {
		disconnect(ftpClient);
	}
	return result;
}
 
开发者ID:yunjiweidian,项目名称:TITAN,代码行数:23,代码来源:FtpUtils.java

示例4: decodeSampledBitmapFromUri

import java.io.BufferedInputStream; //导入依赖的package包/类
public Bitmap decodeSampledBitmapFromUri(Uri fileUri, int reqWidth, int reqHeight)
        throws IOException {
    InputStream stream = new BufferedInputStream(
            mApplicationContext.getContentResolver().openInputStream(fileUri));
    stream.mark(stream.available());
    BitmapFactory.Options options = new BitmapFactory.Options();
    // First decode with inJustDecodeBounds=true to check dimensions
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeStream(stream, null, options);
    stream.reset();
    options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
    options.inJustDecodeBounds = false;
    BitmapFactory.decodeStream(stream, null, options);
    // Decode bitmap with inSampleSize set
    stream.reset();
    return BitmapFactory.decodeStream(stream, null, options);
}
 
开发者ID:firebase,项目名称:friendlypix-android,代码行数:18,代码来源:NewPostUploadTaskFragment.java

示例5: loadFileAsString

import java.io.BufferedInputStream; //导入依赖的package包/类
/**
 * Load UTF8withBOM or any ansi text file.
 *
 * @throws java.io.IOException
 */
public static String loadFileAsString(String filename) throws java.io.IOException {
    final int BUFLEN = 1024;
    BufferedInputStream is = new BufferedInputStream(new FileInputStream(filename), BUFLEN);
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream(BUFLEN);
        byte[] bytes = new byte[BUFLEN];
        boolean isUTF8 = false;
        int read, count = 0;
        while ((read = is.read(bytes)) != -1) {
            if (count == 0 && bytes[0] == (byte) 0xEF && bytes[1] == (byte) 0xBB && bytes[2] == (byte) 0xBF) {
                isUTF8 = true;
                baos.write(bytes, 3, read - 3); // drop UTF8 bom marker
            } else {
                baos.write(bytes, 0, read);
            }
            count += read;
        }
        return isUTF8 ? new String(baos.toByteArray(), "UTF-8") : new String(baos.toByteArray());
    } finally {
        try {
            is.close();
        } catch (Exception ex) {
        }
    }
}
 
开发者ID:dji-sdk,项目名称:Android-Bridge-App,代码行数:31,代码来源:Utils.java

示例6: zipFile

import java.io.BufferedInputStream; //导入依赖的package包/类
/**
 * 压缩文件
 *
 * @param resFile  需要压缩的文件(夹)
 * @param zipout   压缩的目的文件
 * @param rootpath 压缩的文件路径
 * @throws FileNotFoundException 找不到文件时抛出
 * @throws IOException           当压缩过程出错时抛出
 */
public static void zipFile(File resFile, ZipOutputStream zipout, String rootpath)
        throws FileNotFoundException, IOException {
    rootpath = rootpath + (rootpath.trim().length() == 0 ? "" : File.separator)
            + resFile.getName();
    rootpath = new String(rootpath.getBytes("8859_1"), "GB2312");
    if (resFile.isDirectory()) {
        File[] fileList = resFile.listFiles();
        for (File file : fileList) {
            zipFile(file, zipout, rootpath);
        }
    } else {
        byte buffer[] = new byte[BUFF_SIZE];
        BufferedInputStream in = new BufferedInputStream(new FileInputStream(resFile),
                BUFF_SIZE);
        zipout.putNextEntry(new ZipEntry(rootpath));
        int realLength;
        while ((realLength = in.read(buffer)) != -1) {
            zipout.write(buffer, 0, realLength);
        }
        in.close();
        zipout.flush();
        zipout.closeEntry();
    }
}
 
开发者ID:tututututututu,项目名称:BaseCore,代码行数:34,代码来源:ZipUtils.java

示例7: testSkipiTXt

import java.io.BufferedInputStream; //导入依赖的package包/类
/**
 * Tests whether iTXt chunks are successfully skipped without losing
 * any other image data.
 */
@Test
public void testSkipiTXt() throws IOException {

  final InputStream ein = new FileInputStream(no_iTXt);
  final byte[] expected = IOUtils.toByteArray(ein);
  ein.close();

  final InputStream rin =
    new PNGChunkSkipInputStream(Collections.singleton(PNGDecoder.iTXt),
    new BufferedInputStream(new FileInputStream(iTXt))
  );
  final byte[] result = IOUtils.toByteArray(rin);
  rin.close();

  assertArrayEquals(expected, result);
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:21,代码来源:PNGChunkSkipInputStreamTest.java

示例8: connect

import java.io.BufferedInputStream; //导入依赖的package包/类
void connect() throws IOException {
    System.out.println("Client: connect to server");
    try (
            BufferedInputStream bis = new BufferedInputStream(
                    socket.getInputStream());
            BufferedOutputStream bos = new BufferedOutputStream(
                    socket.getOutputStream())) {
        bos.write('x');
        bos.flush();

        int read = bis.read();
        if (read < 0) {
            throw new IOException("Client: couldn't read a response");
        }
        socket.getSession().invalidate();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:DisabledAlgorithms.java

示例9: load

import java.io.BufferedInputStream; //导入依赖的package包/类
/**
 * Loads an xml file without doing xml validation and return a {@link XmlDocument}
 *
 * @param displayName the xml file display name.
 * @param xmlFile the xml file.
 * @return the initialized {@link XmlDocument}
 */
public static XmlDocument load(
        KeyResolver<String> selectors,
        KeyBasedValueResolver<SystemProperty> systemPropertyResolver,
        String displayName,
        File xmlFile,
        XmlDocument.Type type,
        Optional<String> mainManifestPackageName)
        throws IOException, SAXException, ParserConfigurationException {
    InputStream inputStream = new BufferedInputStream(new FileInputStream(xmlFile));

    PositionXmlParser positionXmlParser = new PositionXmlParser();
    Document domDocument = positionXmlParser.parse(inputStream);
    return domDocument != null
            ? new XmlDocument(positionXmlParser,
            new SourceLocation(displayName, xmlFile),
            selectors,
            systemPropertyResolver,
            domDocument.getDocumentElement(),
            type,
            mainManifestPackageName)
            : null;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:30,代码来源:XmlLoader.java

示例10: getMD5

import java.io.BufferedInputStream; //导入依赖的package包/类
/**
 * Returns the md5 hash of a file in hex form.
 * @param file the file to hash
 * @return the md5 hash
 */
public static String getMD5(File file) {
	try {
		InputStream in = new BufferedInputStream(new FileInputStream(file));
		MessageDigest md = MessageDigest.getInstance("MD5");
		byte[] buf = new byte[4096];

		while (true) {
			int len = in.read(buf);
			if (len < 0)
				break;
			md.update(buf, 0, len);
		}
		in.close();

		byte[] md5byte = md.digest();
		StringBuilder result = new StringBuilder();
		for (byte b : md5byte)
			result.append(String.format("%02x", b));
		return result.toString();
	} catch (NoSuchAlgorithmException | IOException e) {
		System.err.println("Failed to calculate MD5 hash.");
	}
	return null;
}
 
开发者ID:housq,项目名称:osu-beatmap-utils,代码行数:30,代码来源:Utils.java

示例11: In

import java.io.BufferedInputStream; //导入依赖的package包/类
/**
 * Initializes an input stream from a URL.
 *
 * @param  url the URL
 * @throws IllegalArgumentException if cannot open {@code url}
 * @throws NullPointerException if {@code url} is {@code null}
 */
public In(URL url) {
    if (url == null) throw new NullPointerException("argument is null");
    try {
        URLConnection site = url.openConnection();
        InputStream is     = site.getInputStream();
        scanner            = new Scanner(new BufferedInputStream(is), CHARSET_NAME);
        scanner.useLocale(LOCALE);
    }
    catch (IOException ioe) {
        throw new IllegalArgumentException("Could not open " + url);
    }
}
 
开发者ID:OpenBW,项目名称:TSBW4J,代码行数:20,代码来源:In.java

示例12: loadGameSave

import java.io.BufferedInputStream; //导入依赖的package包/类
/**
 * Loads the requested {@link GameSaveInterface} from the requested file
 *
 * @param gameSaveFile The file from which to get the save
 *
 * @return the {@link GameSaveInterface} stored into the given file
 * @throws UnableToLoadSaveException if a problem happens during the loading of the save, for example if the file can't
 *                                   be opened or the content of the file isn't a serialized {@link GameSaveInterface}
 */
public static GameSaveInterface loadGameSave(File gameSaveFile) throws UnableToLoadSaveException {
    // We check the file's integrity, if the save is acceptable.
    if (!gameSaveFile.isFile() || !gameSaveFile.getName().endsWith(GameSaver.GAME_SAVES_FILES_EXTENSION)) {
        throw new UnableToLoadSaveException();
    }

    // We try to load the GameSave from the file. If an error happens, we throw an Exception
    try {
        ObjectInputStream objectInputStream = new ObjectInputStream(new BufferedInputStream(new FileInputStream(gameSaveFile)));

        GameSaveInterface gameSave = (GameSaveInterface) objectInputStream.readObject();
        objectInputStream.close();

        return gameSave;
    } catch (IOException | ClassNotFoundException e) {
        throw new UnableToLoadSaveException();
    }
}
 
开发者ID:Chrisp1tv,项目名称:ScrabbleGame,代码行数:28,代码来源:GameSaver.java

示例13: SSLContextPinner

import java.io.BufferedInputStream; //导入依赖的package包/类
public SSLContextPinner(String pemAssetName) {
    try {
        KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
        keyStore.load(null, null);
        InputStream certInputStream = getAssets().open(pemAssetName);
        BufferedInputStream bis = new BufferedInputStream(certInputStream);
        CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
        int idx = -1;
        while (bis.available() > 0) {
            Certificate cert = certificateFactory.generateCertificate(bis);
            keyStore.setCertificateEntry("" + ++idx, cert);
            Log.i("App", "pinned " + idx + ": " + ((X509Certificate) cert).getSubjectDN());
        }
        TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
        trustManagerFactory.init(keyStore);
        TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
        trustManager = trustManagers[0];
        sslContext = SSLContext.getInstance("TLS");
        sslContext.init(null, trustManagers, null);
    } catch(Exception e) {
        sslContext = null;
        trustManager = null;
        Log.e("App", e.toString());
    }
}
 
开发者ID:approov,项目名称:hands-on-api-proxy,代码行数:26,代码来源:App.java

示例14: openInputStream

import java.io.BufferedInputStream; //导入依赖的package包/类
public InputStream openInputStream() throws IOException
{
  // Get the inputstream from the connection to avoid duplicate calls
  // to URL.openConnection
  _lastModifiedTime = URLUtils.getLastModified(_url);
  URLConnection connection = _url.openConnection();

  // avoid URL caching
  // if we use URL caching the files which changed do not get loaded completely
  connection.setUseCaches(false);

  // In theory, should not need to close
  InputStream base = connection.getInputStream();

  if (base instanceof BufferedInputStream)
    return base;
  else
    return new BufferedInputStream(base);
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:20,代码来源:URLInputStreamProvider.java

示例15: LearnerHandler

import java.io.BufferedInputStream; //导入依赖的package包/类
LearnerHandler(Socket sock, BufferedInputStream bufferedInput,
               Leader leader) throws IOException {
    super("LearnerHandler-" + sock.getRemoteSocketAddress());
    this.sock = sock;
    this.leader = leader;
    this.bufferedInput = bufferedInput;
    try {
        leader.self.authServer.authenticate(sock,
                new DataInputStream(bufferedInput));
    } catch (IOException e) {
        LOG.error("Server failed to authenticate quorum learner, addr: {}, closing connection",
                sock.getRemoteSocketAddress(), e);
        try {
            sock.close();
        } catch (IOException ie) {
            LOG.error("Exception while closing socket", ie);
        }
        throw new SaslException("Authentication failure: " + e.getMessage());
    }
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:21,代码来源:LearnerHandler.java


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