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


Java BufferedInputStream.available方法代码示例

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


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

示例1: getTrustManagerFactory

import java.io.BufferedInputStream; //导入方法依赖的package包/类
@Override
public Pair<TrustManagerFactory, KeyManagerFactory> getTrustManagerFactory() {
    try {
        KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
        trustStore.load(null);
        InputStream stream = this.getAssets().open("server.crt");
        BufferedInputStream bis = new BufferedInputStream(stream);
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        while (bis.available() > 0) {
            Certificate cert = cf.generateCertificate(bis);
            trustStore.setCertificateEntry("cert" + bis.available(), cert);
        }
        KeyManagerFactory kmfactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
        kmfactory.init(trustStore, "1234".toCharArray());
        TrustManagerFactory tmf=TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
        tmf.init(trustStore);
        return new Pair<>(tmf, kmfactory);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:rctl,项目名称:CryptoVoice,代码行数:23,代码来源:Main.java

示例2: installPkcs12

import java.io.BufferedInputStream; //导入方法依赖的package包/类
/**
 * This method will launch an intent to install the key chain
 */
private void installPkcs12() {
    try {
        BufferedInputStream bis = new BufferedInputStream(getAssets().open(
                PKCS12_FILENAME));
        byte[] keychain = new byte[bis.available()];
        bis.read(keychain);

        Intent installIntent = KeyChain.createInstallIntent();
        installIntent.putExtra(KeyChain.EXTRA_PKCS12, keychain);
        installIntent.putExtra(KeyChain.EXTRA_NAME, DEFAULT_ALIAS);
        startActivityForResult(installIntent, INSTALL_KEYCHAIN_CODE);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:19,代码来源:KeyChainDemoActivity.java

示例3: 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

示例4: readInputStream

import java.io.BufferedInputStream; //导入方法依赖的package包/类
/**
 * @param bin
 * @return
 * @throws IOException
 */
public static String readInputStream(BufferedInputStream bin) throws IOException {
	if (bin == null) {
		return null;
	}
	byte data[] = null;
	int s = bin.read();
	if (s == -1) {
		return null; //Connection lost
	}
	int alength = bin.available();
	if (alength > 0) {
		data = new byte[alength + 1];

		bin.read(data, 1, alength);
	} else {
		data = new byte[1];
	}
	data[0] = (byte) s;
	return new String(data);
}
 
开发者ID:costea7,项目名称:ChronoBike,代码行数:26,代码来源:StreamUtil.java

示例5: read

import java.io.BufferedInputStream; //导入方法依赖的package包/类
public static byte[] read(File bFile) throws IOException{
  BufferedInputStream bf = new BufferedInputStream(
    new FileInputStream(bFile));
  try {
    byte[] data = new byte[bf.available()];
    bf.read(data);
    return data;
  } finally {
    bf.close();
  }
}
 
开发者ID:sean417,项目名称:LearningOfThinkInJava,代码行数:12,代码来源:BinaryFile.java

示例6: recv

import java.io.BufferedInputStream; //导入方法依赖的package包/类
public byte[] recv(Socket socket) throws DisconnectedException, ReadTimeoutException {
	try {
		BufferedInputStream inStream = new BufferedInputStream(socket.getInputStream());
		if (timestamp == 0)
			timestamp = System.currentTimeMillis();
		while (!new String(buffer).contains(packetDelimiter)) {
			// Disconnected
			long time = System.currentTimeMillis() - timestamp;
			if (time >= TIMEOUT) {
				clear();
				throw new DisconnectedException();
			}
			// Timeout
			if (inStream.available() < 2)
				throw new ReadTimeoutException();
			timestamp = System.currentTimeMillis();
			// Read
			byte[] read = new byte[100000];
			int numRead = inStream.read(read);
			read = Arrays.copyOfRange(read, 0, numRead);
			// Combine saved and new bytes
			byte[] newBytes = new byte[buffer.length + read.length];
			System.arraycopy(buffer, 0, newBytes, 0, buffer.length);
			System.arraycopy(read, 0, newBytes, buffer.length, read.length);
			// Save
			buffer = newBytes;
		}
		int index = Bytes.indexOf(buffer, packetDelimiter.getBytes());
		byte[] packet = Arrays.copyOfRange(buffer, 0, index);
		buffer = Arrays.copyOfRange(buffer, index + packetDelimiter.length(), buffer.length);
		return decode(packet);
	}
	catch (IOException e) {
		Logger.exception(e);
		clear();
		throw new DisconnectedException();
	}
}
 
开发者ID:rolandoislas,项目名称:drc-sim-client,代码行数:39,代码来源:NetUtil.java

示例7: getContentsOfUnicodeFile

import java.io.BufferedInputStream; //导入方法依赖的package包/类
public static char[] getContentsOfUnicodeFile(String filePath) throws IOException {
    BufferedInputStream in = new BufferedInputStream(new FileInputStream(filePath));
    int fileSize = in.available();
    if (fileSize < 2) {
        in.close();
        return null;
    }
    byte[] fileBytes = new byte[fileSize];
    in.read(fileBytes);
    in.close();

    int firstByte = unsignedByteToInt(fileBytes[0]);
    int secondByte = unsignedByteToInt(fileBytes[1]);
    String charSetName = "";
    int startIndex = 0;
    if (firstByte == 0xfe && secondByte == 0xff) {
        charSetName = "UTF-16BE";
        startIndex = 2;
    } else if (firstByte == 0xff && secondByte == 0xfe) {
        charSetName = "UTF-16LE";
        startIndex = 2;
    } else if (firstByte == 0xef) {
        charSetName = "UTF-8";
        startIndex = 3;
    } else if (firstByte == 0x0c && secondByte <= 0xef) { // TODO Make this check language independent
        charSetName = "UTF-16BE";
    } else if (secondByte == 0x0c && firstByte <= 0xef) {
        charSetName = "UTF-16LE";
    }

    InputStreamReader isr = new InputStreamReader(
            new ByteArrayInputStream(fileBytes, startIndex, fileSize - startIndex), charSetName);

    int arraySize = startIndex > 0 ? ((fileSize / startIndex) - 1) : (fileSize / 2);
    char[] fileChars = new char[arraySize];
    for (int i = 0, c; (c = isr.read()) != -1; i++) {
        fileChars[i] = (char) c;
    }
    return fileChars;
}
 
开发者ID:bhashiniservices,项目名称:g2p,代码行数:41,代码来源:G2P_Base.java

示例8: readWholeFile

import java.io.BufferedInputStream; //导入方法依赖的package包/类
public static StringBuilder readWholeFile(String csFile)
	{		
		BufferedInputStream buf = openRead(csFile);
		if(buf == null)
			return null;
	
		StringBuilder sbOut = new StringBuilder();
		boolean bContinue = true;
		try
		{
			int n=0;
			while(bContinue && buf.available() > 0)
			{
				char cChar = (char)buf.read();
//				if(n == 1140 || cChar== '�' || cChar== '�')
//				{
//					int gg =0 ;
//				}
//				
//				
//				
				sbOut.append(cChar);
				n++;
			}
		}
		catch (IOException e)
		{
			closeFile(buf);
			return null;
		}
		closeFile(buf);
		return sbOut;
	}
 
开发者ID:costea7,项目名称:ChronoBike,代码行数:34,代码来源:FileSystem.java

示例9: 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

示例10: genericV8Test

import java.io.BufferedInputStream; //导入方法依赖的package包/类
public Double genericV8Test(final String benchmark, final String testPath) throws Throwable {

        System.out.println("genericV8Test");
        if (!checkV8Presence()) {
            return null;
        }
        final String v8shell = System.getProperty("v8.shell.full.path");
        final PrintStream systemOut = System.out;

        try {

            final Process process = Runtime.getRuntime().exec(v8shell + " " + testPath);
            process.waitFor();
            final InputStream processOut = process.getInputStream();
            final BufferedInputStream bis = new BufferedInputStream(processOut);

            final byte[] output = new byte[bis.available()];
            bis.read(output, 0, bis.available());
            final List<String> result = outputToStrings(output);
            return filterBenchmark(result, benchmark);

        } catch (final Throwable e) {
            System.setOut(systemOut);
            e.printStackTrace();
            throw e;
        }
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:OctaneTest.java

示例11: readExecRemoteOutput

import java.io.BufferedInputStream; //导入方法依赖的package包/类
/**
 * Read the remote output for the exec channel. This is the code provided on the jcraft site with a timeout added.
 *
 * @param channelExec the exec channel
 * @param timeout     the maximum period of time for reading the channel output
 * @return the output from the channel
 * @throws IOException for any issues encoutered when retrieving the input stream from the channel
 */
private String readExecRemoteOutput(ChannelExec channelExec, long timeout) throws IOException {
    final BufferedInputStream bufIn = new BufferedInputStream(channelExec.getInputStream());
    final StringBuilder outputBuilder = new StringBuilder();

    final byte[] tmp = new byte[BYTE_CHUNK_SIZE];
    final long startTime = System.currentTimeMillis();
    final long readLoopSleepTime = Long.parseLong(ApplicationProperties.get(
            JSCH_EXEC_READ_REMOTE_OUTPUT_LOOP_SLEEP_TIME.getPropertyName(), READ_LOOP_SLEEP_TIME_DEFAULT_VALUE));

    while (true) {
        // read the stream
        while (bufIn.available() > 0) {
            int i = bufIn.read(tmp, 0, BYTE_CHUNK_SIZE);
            if (i < 0) {
                break;
            }
            outputBuilder.append(new String(tmp, 0, i, StandardCharsets.UTF_8));
        }

        // check if the channel is closed
        if (channelExec.isClosed()) {
            // check for any more bytes on the input stream
            sleep(readLoopSleepTime);

            if (bufIn.available() > 0) {
                continue;
            }

            LOGGER.debug("exit-status: {}", channelExec.getExitStatus());
            break;
        }

        // check timeout
        if ((System.currentTimeMillis() - startTime) > timeout) {
            LOGGER.warn("Remote exec output reading timeout!");
            break;
        }

        // If for some reason the channel is not getting closed, we should not hog CPU time with this loop hence
        // we sleep for a while
        sleep(readLoopSleepTime);
    }
    return outputBuilder.toString();
}
 
开发者ID:cerner,项目名称:jwala,代码行数:53,代码来源:JschServiceImpl.java

示例12: readRemoteOutput

import java.io.BufferedInputStream; //导入方法依赖的package包/类
/**
 * Reads data streamed from a remote connection
 *
 * @param remoteOutput  the inputstream where the remote connection will stream data to
 * @param dataEndMarker a marker which tells the method to stop reading from the inputstream. If this is null
 *                      then the method will try to read data from the input stream until read timeout is reached.
 * @param timeout       the length of time in which to wait for incoming data from the stream
 * @return the data streamed from the remote connection
 * @throws IOException thrown when reading bytes from input stream
 */
private String readRemoteOutput(final InputStream remoteOutput, final Character dataEndMarker, final long timeout)
        throws IOException {

    if (null == dataEndMarker) {
        throw new JschServiceException("Expecting non-null end marker when reading remote output");
    }

    final int readInputSleepDuration = Integer.parseInt(ApplicationProperties.get(
            JSCH_CHANNEL_SHELL_READ_INPUT_SLEEP_DURATION.getPropertyName(), SHELL_READ_SLEEP_DEFAULT_VALUE));
    final BufferedInputStream buffIn = new BufferedInputStream(remoteOutput);
    final byte[] bytes = new byte[BYTE_CHUNK_SIZE];
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    String result;
    LOGGER.debug("Default char encoding:" + Charset.defaultCharset());
    long startTime = System.currentTimeMillis();
    try {
        while (true) {
            if (buffIn.available() != 0) {
                final int size = buffIn.read(bytes);

                if (size > 0) {
                    LOGGER.debug("Read:" + size + " bytes");
                    out.write(bytes, 0, size);
                    LOGGER.debug("Bytes read as String: " + new String(bytes));
                }

                startTime = System.currentTimeMillis();

                // Alternative method of checking if we got our 'EOF' character.
                boolean stopReading = false;
                for(int b=0;b<size;b++) {
                    if (bytes[b]==-1) {
                        LOGGER.debug("Read EOF byte '{}', stopping remote output reading...", bytes[size - 1]);
                        stopReading=true;
                    }
                }

                if (stopReading) {
                    break;
                }

                // need to verify this works on non-windows systems
                // currently setting the encoding to UTF8, UTF16, ASCII, or ISO all fail this conditional
                // e.g. new String(bytes, StandardCharsets.UTF-8)
                // printing out Charset.defaultCharset() shows it's using windows-1252 on a Windows JVM
                if (new String(bytes).indexOf(dataEndMarker) > -1) {
                    LOGGER.debug("Read EOF character '{}', stopping remote output reading...", bytes[size - 1]);
                    break;
                }
            }

            if ((System.currentTimeMillis() - startTime) > timeout) {
                LOGGER.warn("Remote output reading timeout!");
                break;
            }

            try {
                Thread.sleep(readInputSleepDuration);
            } catch (final InterruptedException e) {
                final String errMsg =  "readRemoteOutput was interrupted while waiting for input from JSch channel!";
                LOGGER.error(errMsg, e);
                throw new JschServiceException(errMsg, e);
            }
        }
    } finally {
        result = out.toString(StandardCharsets.UTF_8.name());
        out.close();
    }

    return result;
}
 
开发者ID:cerner,项目名称:jwala,代码行数:82,代码来源:JschServiceImpl.java


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