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


Java InputStream.available方法代码示例

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


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

示例1: loadJSONFromAsset

import java.io.InputStream; //导入方法依赖的package包/类
private String loadJSONFromAsset() {
  String json;
  try {
    InputStream is = getAssets().open("quotes.json");
    int size = is.available();
    byte[] buffer = new byte[size];
    //noinspection ResultOfMethodCallIgnored
    is.read(buffer);
    is.close();
    json = new String(buffer, "UTF-8");
  } catch (IOException ex) {
    Log.e(TAG, "loadJSONFromAsset", ex);
    return null;
  }
  return json;
}
 
开发者ID:DevAhamed,项目名称:MultiViewAdapter,代码行数:17,代码来源:SimpleAdapterActivity.java

示例2: loadResource

import java.io.InputStream; //导入方法依赖的package包/类
public static Mat loadResource(Context context, int resourceId, int flags) throws IOException
{
    InputStream is = context.getResources().openRawResource(resourceId);
    ByteArrayOutputStream os = new ByteArrayOutputStream(is.available());

    byte[] buffer = new byte[4096];
    int bytesRead;
    while ((bytesRead = is.read(buffer)) != -1) {
        os.write(buffer, 0, bytesRead);
    }
    is.close();

    Mat encoded = new Mat(1, os.size(), CvType.CV_8U);
    encoded.put(0, 0, os.toByteArray());
    os.close();

    Mat decoded = Imgcodecs.imdecode(encoded, flags);
    encoded.release();

    return decoded;
}
 
开发者ID:johnhany,项目名称:MOAAP,代码行数:22,代码来源:Utils.java

示例3: getBase64FromFile

import java.io.InputStream; //导入方法依赖的package包/类
/**
 * 将图片文件转化为字节数组字符串,并对其进行Base64编码处理
 *
 * @param header   头部信息
 * @param filePath 本地路径
 * @return Base64编码
 */
public static String getBase64FromFile(String header, String filePath) {
    if (filePath == null || filePath.length() == 0) {
        return "File path does not exist!";
    }

    byte[] data = null;
    try {
        InputStream in = new FileInputStream(filePath);
        data = new byte[in.available()];
        in.read(data);
        in.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

    // 对字节数组Base64编码
    return header != null ? header + Base64.encodeToString(data, Base64.DEFAULT) : Base64.encodeToString(data, Base64.DEFAULT);
}
 
开发者ID:RockyQu,项目名称:MVVMFrames,代码行数:26,代码来源:FileUtils.java

示例4: CBZip2InputStream

import java.io.InputStream; //导入方法依赖的package包/类
private CBZip2InputStream(final InputStream in, READ_MODE readMode, boolean skipDecompression)
    throws IOException {

  super();
  int blockSize = 0X39;// i.e 9
  this.blockSize100k = blockSize - '0';
  this.in = new BufferedInputStream(in, 1024 * 9);// >1 MB buffer
  this.readMode = readMode;
  this.skipDecompression = skipDecompression;
  if (readMode == READ_MODE.CONTINUOUS) {
    currentState = STATE.START_BLOCK_STATE;
    lazyInitialization = (in.available() == 0)?true:false;
    if(!lazyInitialization){
  init();
}
  } else if (readMode == READ_MODE.BYBLOCK) {
    this.currentState = STATE.NO_PROCESS_STATE;
    skipResult = this.skipToNextMarker(CBZip2InputStream.BLOCK_DELIMITER,DELIMITER_BIT_LENGTH);
    this.reportedBytesReadFromCompressedStream = this.bytesReadFromCompressedStream;
    if(!skipDecompression){
      changeStateToProcessABlock();
    }
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:25,代码来源:CBZip2InputStream.java

示例5: copyStream

import java.io.InputStream; //导入方法依赖的package包/类
public static boolean copyStream(InputStream is, OutputStream os, CopyListener listener, int bufferSize) throws IOException {
    int current = 0;
    int total = is.available();
    if (total <= 0) {
        total = DEFAULT_IMAGE_TOTAL_SIZE;
    }
    byte[] bytes = new byte[bufferSize];
    if (shouldStopLoading(listener, 0, total)) {
        return false;
    }
    do {
        int count = is.read(bytes, 0, bufferSize);
        if (count != -1) {
            os.write(bytes, 0, count);
            current += count;
        } else {
            os.flush();
            return true;
        }
    } while (!shouldStopLoading(listener, current, total));
    return false;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:23,代码来源:IoUtils.java

示例6: testStorageAppendFileCommand

import java.io.InputStream; //导入方法依赖的package包/类
/**
 * 文件续传需要先使用 append模式Save一个可以续传的文件
 * 然后才能使用续传命令续传文件
 * 
 * @throws IOException
 */
@Test
public void testStorageAppendFileCommand() throws IOException {
    String firstText = "Tobato is a good man.他是一个好人\r\n";
    InputStream firstIn = getTextInputStream(firstText);
    long firstSize = firstIn.available();
    // 先上载第一段文字
    StorePath path = uploadInputStream(firstIn, "txt", firstSize, true);
    // 添加第二段文字
    String secendText = "Work hard and hard. 努力工作啊\r\n";
    InputStream secendIn = getTextInputStream(secendText);
    long secendSize = secendIn.available();
    // 文件续传
    execStorageAppendFileCommand(secendIn, secendSize, path.getPath());
    firstIn.close();
    secendIn.close();
}
 
开发者ID:whatodo,项目名称:FastDFS_Client,代码行数:23,代码来源:StorageAppendFileCommandTest.java

示例7: copyStream

import java.io.InputStream; //导入方法依赖的package包/类
/**
 * Copies stream, fires progress events by listener, can be interrupted by listener.
 *
 * @param is         Input stream
 * @param os         Output stream
 * @param listener   null-ok; Listener of copying progress and controller of copying interrupting
 * @param bufferSize Buffer size for copying, also represents a step for firing progress listener callback, i.e.
 *                   progress event will be fired after every copied <b>bufferSize</b> bytes
 * @return <b>true</b> - if stream copied successfully; <b>false</b> - if copying was interrupted by listener
 * @throws IOException
 */
public static boolean copyStream(InputStream is, OutputStream os, CopyListener listener, int bufferSize)
		throws IOException {
	int current = 0;
	int total = is.available();
	if (total <= 0) {
		total = DEFAULT_IMAGE_TOTAL_SIZE;
	}

	final byte[] bytes = new byte[bufferSize];
	int count;
	if (shouldStopLoading(listener, current, total)) return false;
	while ((count = is.read(bytes, 0, bufferSize)) != -1) {
		os.write(bytes, 0, count);
		current += count;
		if (shouldStopLoading(listener, current, total)) return false;
	}
	os.flush();
	return true;
}
 
开发者ID:siwangqishiq,项目名称:ImageLoaderSupportGif,代码行数:31,代码来源:IoUtils.java

示例8: doGet

import java.io.InputStream; //导入方法依赖的package包/类
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
   {
String path = request.getRequestURI().substring(request.getServletPath().length());

InputStream resource = ClassLoader.getSystemResourceAsStream("org/apache/zookeeper/graph/resources" + path);	  
if (resource == null) {
    response.getWriter().println(path + " not found!");
    response.setStatus(HttpServletResponse.SC_NOT_FOUND);
    return;
}
try {
  while (resource.available() > 0) {
    response.getWriter().write(resource.read());
  }
} finally {
  resource.close();
}
//        response.setContentType("text/plain;charset=utf-8");
       response.setStatus(HttpServletResponse.SC_OK);
   }
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:21,代码来源:StaticContent.java

示例9: MicToken

import java.io.InputStream; //导入方法依赖的package包/类
public MicToken(Krb5Context context, MessageProp prop,
                InputStream data)
      throws GSSException, IOException {
      super(Krb5Token.MIC_ID, context);
      byte[] dataBytes = new byte[data.available()];
      data.read(dataBytes);

      //debug("Application data to MicToken cons is [" +
      //     getHexBytes(dataBytes) + "]\n");
      if (prop == null) prop = new MessageProp(0, false);
      genSignAndSeqNumber(prop, null, dataBytes, 0, dataBytes.length, null);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:MicToken.java

示例10: loadJSONFromAsset

import java.io.InputStream; //导入方法依赖的package包/类
public static String loadJSONFromAsset(Context context, String filename) {
    String json = null;
    try {
        InputStream is = context.getAssets().open(filename);
        int size = is.available();
        byte[] buffer = new byte[size];
        is.read(buffer);
        is.close();
        json = new String(buffer, "UTF-8");
    } catch (IOException ex) {
        ex.printStackTrace();
        return null;
    }
    return json;
}
 
开发者ID:afiqiqmal,项目名称:ConcealSharedPreference-Android,代码行数:16,代码来源:Data.java

示例11: aroundReadFrom

import java.io.InputStream; //导入方法依赖的package包/类
@Override
public Object aroundReadFrom(ReaderInterceptorContext interceptorContext)
		throws IOException, WebApplicationException {
	logger.info("ClientFirstReaderInterceptor invoked");
	InputStream inputStream = interceptorContext.getInputStream();
	byte[] bytes = new byte[inputStream.available()];
	inputStream.read(bytes);
	String requestContent = new String(bytes);
	requestContent = requestContent + ".Request changed in ClientFirstReaderInterceptor.";
	interceptorContext.setInputStream(new ByteArrayInputStream(requestContent.getBytes()));
	return interceptorContext.proceed();
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:13,代码来源:ClientFirstReaderInterceptor.java

示例12: readMessageData

import java.io.InputStream; //导入方法依赖的package包/类
private byte[] readMessageData(InputStream is) throws IOException {
    if (is.available() > 0) {
        byte[] result = new byte[is.available()];
        is.read(result);
        return result;
    }
    return new byte[]{};
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:9,代码来源:DubboCodec.java

示例13: locateBytes

import java.io.InputStream; //导入方法依赖的package包/类
private byte[] locateBytes() throws IOException {
    try {
        JarFile jar = new JarFile("Agent.jar");
        InputStream is = jar.getInputStream(jar.getEntry("Agent.class"));
        int len = is.available();
        byte[] buf = new byte[len];
        DataInputStream in = new DataInputStream(is);
        in.readFully(buf);
        return buf;
    } catch (IOException ioe) {
        ioe.printStackTrace();
        throw new IOException("Test failed due to IOException!");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:CustomLoader.java

示例14: injectMaterialCSS

import java.io.InputStream; //导入方法依赖的package包/类
private void injectMaterialCSS(String mode) {
	try {
		InputStream inputStream = getAssets().open("makitheme.css");
		byte[] buffer = new byte[inputStream.available()];
		inputStream.read(buffer);
		inputStream.close();
		webView.loadUrl("javascript:(function() {var parent = document.getElementsByTagName('head').item(0);var style = document.createElement('style');style.type = 'text/css';style.innerHTML = window.atob('" + Base64.encodeToString(buffer, 2) + "');" + "parent.appendChild(style)" + "})()");
	} catch (Exception fb) {
		fb.printStackTrace();
	}
}
 
开发者ID:sfilmak,项目名称:MakiLite,代码行数:12,代码来源:StandartMessages.java

示例15: getMemInputStream

import java.io.InputStream; //导入方法依赖的package包/类
private InputStream getMemInputStream(JarFile jf, JarEntry je)
throws IOException {
    InputStream is = getInputStream4336753(jf, je);
    ByteArrayOutputStream os = new ByteArrayOutputStream(is.available());

    try {
        FileUtil.copy(is, os);
    } finally {
        os.close();
    }

    return new ByteArrayInputStream(os.toByteArray());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:JarFileSystem.java


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