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


Java FileInputStream.available方法代码示例

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


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

示例1: getClassData

import java.io.FileInputStream; //导入方法依赖的package包/类
/**
 * Get the data from the class file for the specified class.  If
 * the file can't be found, or the class is not one of the
 * special ones listed below, return null.
 *    Bug4179766Class
 *    Bug4179766Resource
 */
private byte[] getClassData(String className) {
    boolean shouldLoad = className.equals("Bug4179766Class");
    shouldLoad = shouldLoad || className.equals("Bug4179766Resource");

    if (shouldLoad) {
        try {
            File file = new File(System.getProperty("test.classes", "."), className+CLASS_SUFFIX);
            FileInputStream fi = new FileInputStream(file);
            byte[] result = new byte[fi.available()];
            fi.read(result);
            return result;
        } catch (Exception e) {
            return null;
        }
    } else {
        return null;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:TestBug4179766.java

示例2: fileTxtRead

import java.io.FileInputStream; //导入方法依赖的package包/类
String fileTxtRead(String fileName)
{  
	String res="";
       try
	{
		File file = new File(fileName);  
		FileInputStream fis = new FileInputStream(file);  
		int length = fis.available(); 
		byte [] buffer = new byte[length]; 
		fis.read(buffer);     
		res = EncodingUtils.getString(buffer, "UTF-8"); 
		fis.close();     
	}
	catch (IOException e)
	{
		e.printStackTrace();
	}  
	return res;
}
 
开发者ID:nijigenirubasho,项目名称:mobiletailchanger,代码行数:20,代码来源:MainActivity.java

示例3: getDocument

import java.io.FileInputStream; //导入方法依赖的package包/类
private Document  getDocument(FileObject fo){
    Document result = null;
    if (documentPooling) {
        result = documentPool().get(fo);
    }
    if (result != null) return result;
    try {
        
        File file = FileUtil.toFile(fo);
        FileInputStream fis = new FileInputStream(file);
        byte buffer[] = new byte[fis.available()];
        result = new org.netbeans.editor.BaseDocument(true, fo.getMIMEType());
        result.remove(0, result.getLength());
        fis.read(buffer);
        fis.close();
        String str = new String(buffer);
        result.insertString(0,str,null);
        
    } catch (Exception dObjEx) {
        return null;
    }
    if (documentPooling) {
        documentPool().put(fo, result);
    }
    return result;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:TestCatalogModel.java

示例4: testBinary

import java.io.FileInputStream; //导入方法依赖的package包/类
public void testBinary() throws IOException, ClassificationException {
	File file = new File("src/test/resources/data/SampleData.txt");
	FileInputStream fileInputStream = new FileInputStream(file);
	ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
	int available;
	while ((available = fileInputStream.available()) > 0) {
		byte[] data = new byte[available];
		fileInputStream.read(data);
		byteArrayOutputStream.write(data);
	}
	fileInputStream.close();
	byteArrayOutputStream.close();

	Result result = classificationClient.getClassifiedDocument(byteArrayOutputStream.toByteArray(), "SampleData.txt");
	assertEquals("Article count", 1, result.getArticles().size());

}
 
开发者ID:Smartlogic-Semaphore-Limited,项目名称:Java-APIs,代码行数:18,代码来源:ClassifyBinaryArticlesTest.java

示例5: readFilebyte

import java.io.FileInputStream; //导入方法依赖的package包/类
/**
 * 通过完整路径读取文件的字节流 . <br>
 * @author liulongzhenhai 2012-8-2 上午8:49:55 <br>
 * @param fileFullPath 读取文件路径
 * @return 返回整个文件数据 流
 */
public static byte[] readFilebyte(final String fileFullPath) {
	final File file = getFileObject(fileFullPath);
	if (file != null && file.exists()) {
		try {
			FileInputStream fis = new FileInputStream(file);
			final int readSize = fis.available();
			final byte[] buff = new byte[readSize];
			fis.read(buff);
			fis.close();
			fis = null;
			return buff;
		} catch (final Exception ex) {
			throw new RuntimeException(ex);
		}
	}
	return null;
}
 
开发者ID:VK2012,项目名称:AppCommonFrame,代码行数:24,代码来源:FileUtil.java

示例6: readAidFile

import java.io.FileInputStream; //导入方法依赖的package包/类
public static byte[] readAidFile(String fileName)
{
    byte [] buffer = null;

    try{
        File file = new File(fileName);
        if (!file.exists())
        {
            return null;
        }

        FileInputStream fis = new FileInputStream(file);

        int length = fis.available();
        buffer = new byte[length];
        fis.read(buffer);
        fis.close();
    }
    catch(Exception e){
        e.printStackTrace();
    }

    return buffer;
}
 
开发者ID:changingp,项目名称:qpboc-kata,代码行数:25,代码来源:FileUtil.java

示例7: get

import java.io.FileInputStream; //导入方法依赖的package包/类
public String get(Cursor cursor) {
        //cursor.moveToFirst();
        String lookupKey = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
        Log.d("Vcard lookupKey ", lookupKey);
        Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_VCARD_URI, lookupKey);
        Log.d("Vcard uri ", uri.toString());
        AssetFileDescriptor fd;
        try {
            fd = this.getContentResolver().openAssetFileDescriptor(uri, "r");

            // Your Complex Code and you used function without loop so how can you get all Contacts Vcard.??


           /* FileInputStream fis = fd.createInputStream();
            byte[] buf = new byte[(int) fd.getDeclaredLength()];
            fis.read(buf);
            String VCard = new String(buf);
            String path = Environment.getExternalStorageDirectory().toString() + File.separator + vfile;
            FileOutputStream out = new FileOutputStream(path);
            out.write(VCard.toString().getBytes());
            Log.d("Vcard",  VCard);*/
            //https://stackoverflow.com/questions/42017591/in-android-7-contentresolvers-method-openassetfiledescriptorvcarduri-r-re
            FileInputStream fis = fd.createInputStream();
            byte[] buf = new byte[fis.available()];
            fis.read(buf);
            String vcardstring = new String(buf);
            if(mapVcard.containsKey(uri.toString())){
                String vv=mapVcard.get(uri.toString());
                if(vv.equals(vcardstring)){
                    Log.d("Vcard lookupKey 重复", lookupKey);
                    return vv;
                }
            }

            mapVcard.put(uri.toString(),vcardstring);
            //log.d("write "+vcardstring);
//            FileOutputStream mFileOutputStream = new FileOutputStream(storage_path, true);
            mFileOutputStream.write(buf);//vcardstring.toString().getBytes());
            return vcardstring;

        } catch (Exception e1) {
            e1.printStackTrace();
            log.e(e1);
        }
        return "";
    }
 
开发者ID:yippeesoft,项目名称:NotifyTools,代码行数:47,代码来源:VcardService.java

示例8: testBinary

import java.io.FileInputStream; //导入方法依赖的package包/类
public void testBinary() throws IOException, ClassificationException {
	File file = new File("src/test/resources/data/SampleData.txt");
	FileInputStream fileInputStream = new FileInputStream(file);
	ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
	int available;
	while ((available = fileInputStream.available()) > 0) {
		byte[] data = new byte[available];
		fileInputStream.read(data);
		byteArrayOutputStream.write(data);
	}
	fileInputStream.close();
	byteArrayOutputStream.close();

	Result result1 = classificationClient.getClassifiedDocument(byteArrayOutputStream.toByteArray(), "SampleData.txt");
	assertEquals("Hash 1", "f7be152b1d057570b892dbe3dc39bd70", result1.getHash());

	Map<String, Collection<String>> metadata = new HashMap<String, Collection<String>>();
	Collection<String> cheeses = new Vector<String>();
	cheeses.add("Brie");
	cheeses.add("Camenbert");
	cheeses.add("Cheddar");
	metadata.put("cheeses", cheeses);

	Result result2 = classificationClient.getClassifiedDocument(byteArrayOutputStream.toByteArray(), "SampleData.txt", new Title("title"), metadata);
	assertEquals("Hash 2", "c723555e774c94d0ead71d5c1cc06efc", result2.getHash());

}
 
开发者ID:Smartlogic-Semaphore-Limited,项目名称:Java-APIs,代码行数:28,代码来源:ClassifyDocumentWithHashTest.java

示例9: readFully

import java.io.FileInputStream; //导入方法依赖的package包/类
/**
 * A convenience for {@link #openRead()} that also reads all of the
 * file contents into a byte array which is returned.
 */
public byte[] readFully() throws IOException {
    FileInputStream stream = openRead();
    try {
        int pos = 0;
        int avail = stream.available();
        byte[] data = new byte[avail];
        while (true) {
            int amt = stream.read(data, pos, data.length-pos);
            //Log.i("foo", "Read " + amt + " bytes at " + pos
            //        + " of avail " + data.length);
            if (amt <= 0) {
                //Log.i("foo", "**** FINISHED READING: pos=" + pos
                //        + " len=" + data.length);
                return data;
            }
            pos += amt;
            avail = stream.available();
            if (avail > data.length-pos) {
                byte[] newData = new byte[pos+avail];
                System.arraycopy(data, 0, newData, 0, pos);
                data = newData;
            }
        }
    } finally {
        stream.close();
    }
}
 
开发者ID:7763sea,项目名称:VirtualHook,代码行数:32,代码来源:AtomicFile.java

示例10: getDocument

import java.io.FileInputStream; //导入方法依赖的package包/类
private Document  getDocument(FileObject fo){
    Document result = null;
    if (documentPooling) {
        result = documentPool().get(fo);
    }
    if (result != null) return result;
    try {
        
        File file = FileUtil.toFile(fo);
        FileInputStream fis = new FileInputStream(file);
        byte buffer[] = new byte[fis.available()];
        result = new org.netbeans.editor.BaseDocument(
                org.netbeans.modules.xml.text.syntax.XMLKit.class, false);
        result.remove(0, result.getLength());
        fis.read(buffer);
        fis.close();
        String str = new String(buffer);
        result.insertString(0,str,null);
        
    } catch (Exception dObjEx) {
        return null;
    }
    if (documentPooling) {
        documentPool().put(fo, result);
    }
    return result;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:TestCatalogModel.java

示例11: testBinary

import java.io.FileInputStream; //导入方法依赖的package包/类
public void testBinary() throws IOException, ClassificationException {

		URL log4jXmlUrl = ClassLoader.getSystemResource("log4j.xml");
		if (log4jXmlUrl != null) System.out.println(log4jXmlUrl.toExternalForm());
		File file = new File("src/test/resources/data/SampleData.txt");
		FileInputStream fileInputStream = new FileInputStream(file);
		ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
		int available;
		while ((available = fileInputStream.available()) > 0) {
			byte[] data = new byte[available];
			fileInputStream.read(data);
			byteArrayOutputStream.write(data);
		}
		fileInputStream.close();
		byteArrayOutputStream.close();

		classificationClient.getClassificationConfiguration().setConnectionTimeoutMS(0);
		classificationClient.getClassificationConfiguration().setSocketTimeoutMS(0);

		try {
			Date startDate = new Date();
			classificationClient.getClassifiedDocument(byteArrayOutputStream.toByteArray(), "SampleData.txt");
			Date endDate = new Date();
			assertTrue("Classification took too long: " + (endDate.getTime() - startDate.getTime()) + "ms", (endDate.getTime() - startDate.getTime()) < 100000);
		} catch (Exception e) {
			fail("ClassifyLargeTest failure: " + e.getMessage());
		}

	}
 
开发者ID:Smartlogic-Semaphore-Limited,项目名称:Java-APIs,代码行数:30,代码来源:ClassifyLargeTest.java

示例12: file2Byte

import java.io.FileInputStream; //导入方法依赖的package包/类
/**
 * file转byte
 * @param file 文件名
 * @return byte文件
 * @throws Exception 文件为空
 */
public static byte[] file2Byte(File file) throws Exception {
    FileInputStream fileInputStream = new FileInputStream(file);
    byte[] data = new byte[fileInputStream.available()];
    fileInputStream.read(data);
    fileInputStream.close();
    return data;
}
 
开发者ID:Transwarp-DE,项目名称:Transwarp-Sample-Code,代码行数:14,代码来源:FileUtil.java

示例13: getClassFileBytes

import java.io.FileInputStream; //导入方法依赖的package包/类
protected byte[] getClassFileBytes(String className) 
{
	byte result[] = null;
   	
	if(m_bCanLoadClass)
	{
		String clpack = className.replace('.', '/') ;
 	    for(int n=0; n<m_arrPaths.size(); n++)
    	{
 	    	String csPath = m_arrPaths.get(n);
	    	try 
	    	{
	    		FileInputStream fi = new FileInputStream(csPath + clpack + ".class");
	    	    result = new byte[fi.available()];
	    	    fi.read(result);
	    	    fi.close() ;
	    	    return result;
	    	} 
	    	catch (Exception e) 
	    	{	
	    	}
    	}
	}

	if(m_bCanLoadJar && m_jarEntries != null)
	{
		result = m_jarEntries.loadJarEntry(className);
	}
	return result;
}
 
开发者ID:costea7,项目名称:ChronoBike,代码行数:31,代码来源:ClassDynLoader.java

示例14: getSize

import java.io.FileInputStream; //导入方法依赖的package包/类
public static int getSize(File file) {
	
	int filesize = -1;
	boolean stream = false;
	
	try {
		FileInputStream fis = new FileInputStream(file);
		filesize = fis.available();
		filesize /= 1024;
		fis.close();
	} catch (Exception e) { e.printStackTrace(); }
	
	return filesize;
}
 
开发者ID:Deconimus,项目名称:JarShrink,代码行数:15,代码来源:Files.java

示例15: open

import java.io.FileInputStream; //导入方法依赖的package包/类
@Override
public long open(DataSpec dataSpec) throws ContentDataSourceException {
  try {
    uriString = dataSpec.uri.toString();
    AssetFileDescriptor assetFd = resolver.openAssetFileDescriptor(dataSpec.uri, "r");
    inputStream = new FileInputStream(assetFd.getFileDescriptor());
    long skipped = inputStream.skip(dataSpec.position);
    if (skipped < dataSpec.position) {
      // We expect the skip to be satisfied in full. If it isn't then we're probably trying to
      // skip beyond the end of the data.
      throw new EOFException();
    }
    if (dataSpec.length != C.LENGTH_UNBOUNDED) {
      bytesRemaining = dataSpec.length;
    } else {
      bytesRemaining = inputStream.available();
      if (bytesRemaining == 0) {
        // FileInputStream.available() returns 0 if the remaining length cannot be determined, or
        // if it's greater than Integer.MAX_VALUE. We don't know the true length in either case,
        // so treat as unbounded.
        bytesRemaining = C.LENGTH_UNBOUNDED;
      }
    }
  } catch (IOException e) {
    throw new ContentDataSourceException(e);
  }

  opened = true;
  if (listener != null) {
    listener.onTransferStart();
  }

  return bytesRemaining;
}
 
开发者ID:pooyafaroka,项目名称:PlusGram,代码行数:35,代码来源:ContentDataSource.java


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