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


Java InputStream.close方法代码示例

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


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

示例1: doLocalXMLParser

import java.io.InputStream; //导入方法依赖的package包/类
private void doLocalXMLParser(){
    try {
        //Return an AssetManager instance for your application's package
        InputStream is = getAssets().open("test.xml");
        int size = is.available();
        // Read the entire asset into a local byte buffer.
        byte[] buffer = new byte[size];
        is.read(buffer);
        is.close();

        // Convert the buffer into a string.
        String xmlData = new String(buffer, "UTF-8");
        beginParser(xmlData);
    } catch (IOException e) {
        // Should never happen!
        throw new RuntimeException(e);
    }
}
 
开发者ID:AlawnXu,项目名称:XMLBaseParser,代码行数:19,代码来源:MainActivity.java

示例2: getCMDOutputString

import java.io.InputStream; //导入方法依赖的package包/类
/**
 * Get command output string.
 */
public static String getCMDOutputString(String[] args) {
    try {
        ProcessBuilder cmd = new ProcessBuilder(args);
        Process process = cmd.start();
        InputStream in = process.getInputStream();
        StringBuilder sb = new StringBuilder();
        byte[] re = new byte[64];
        int len;
        while ((len = in.read(re)) != -1) {
            sb.append(new String(re, 0, len));
        }
        in.close();
        process.destroy();
        JLog.i("CMD: " + sb.toString());
        return sb.toString();
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    return null;
}
 
开发者ID:jeasinlee,项目名称:AndroidBasicLibs,代码行数:24,代码来源:CpuUtil.java

示例3: loadData

import java.io.InputStream; //导入方法依赖的package包/类
protected void loadData ( final File file ) throws Exception
{
    if ( OscarLoader.isOscar ( file ) )
    {
        final OscarLoader loader = new OscarLoader ( file );
        this.mergeController.setLocalData ( loader.getData () );
        this.mergeController.setIgnoreFields ( loader.getIgnoreFields () );
    }
    else
    {
        final InputStream stream = new FileInputStream ( file );
        try
        {
            this.mergeController.setLocalData ( OscarLoader.loadJsonData ( stream ) );
        }
        finally
        {
            stream.close ();
        }
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:22,代码来源:LocalDataPage.java

示例4: refresh

import java.io.InputStream; //导入方法依赖的package包/类
public static boolean refresh(){
	props 							= new Properties();
	try {
		URLConnection connection	= new URL("http://kussmaul.net/projects.properties").openConnection();
		connection.setConnectTimeout(1000);
		final InputStream in = connection.getInputStream();
		props.load(in);
		if(!props.containsKey("ServerIP"))
			throw new Exception("Something wrong with download");
		in.close();
		return true;
	} catch (Exception e) {
		e.printStackTrace();
		props						= getDefaultProperties();
		return false;
	}
}
 
开发者ID:CalebKussmaul,项目名称:GIFKR,代码行数:18,代码来源:CalebKussmaul.java

示例5: exportResource

import java.io.InputStream; //导入方法依赖的package包/类
public static String exportResource(Context context, int resourceId, String dirname) {
    String fullname = context.getResources().getString(resourceId);
    String resName = fullname.substring(fullname.lastIndexOf("/") + 1);
    try {
        InputStream is = context.getResources().openRawResource(resourceId);
        File resDir = context.getDir(dirname, Context.MODE_PRIVATE);
        File resFile = new File(resDir, resName);

        FileOutputStream os = new FileOutputStream(resFile);

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

        return resFile.getAbsolutePath();
    } catch (IOException e) {
        e.printStackTrace();
        throw new CvException("Failed to export resource " + resName
                + ". Exception thrown: " + e);
    }
}
 
开发者ID:linzuzeng,项目名称:Microsphere,代码行数:26,代码来源:Utils.java

示例6: testHadoopFileSystem

import java.io.InputStream; //导入方法依赖的package包/类
@Test
@TestHdfs
public void testHadoopFileSystem() throws Exception {
  Configuration conf = TestHdfsHelper.getHdfsConf();
  FileSystem fs = FileSystem.get(conf);
  try {
    OutputStream os = fs.create(new Path(TestHdfsHelper.getHdfsTestDir(), "foo"));
    os.write(new byte[]{1});
    os.close();
    InputStream is = fs.open(new Path(TestHdfsHelper.getHdfsTestDir(), "foo"));
    assertEquals(is.read(), 1);
    assertEquals(is.read(), -1);
    is.close();
  } finally {
    fs.close();
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:18,代码来源:TestHFSTestCase.java

示例7: inputstreamToByteArray

import java.io.InputStream; //导入方法依赖的package包/类
/**
 * Converts an InputStream into a byte array.
 * 
 * @param ins input stream to convert
 * 
 * @return resultant byte array
 * 
 * @throws MetadataProviderException thrown if there is a problem reading the resultant byte array
 */
protected byte[] inputstreamToByteArray(InputStream ins) throws MetadataProviderException {
    try {
        // 1 MB read buffer
        byte[] buffer = new byte[1024 * 1024];
        ByteArrayOutputStream output = new ByteArrayOutputStream();

        int n = 0;
        while (-1 != (n = ins.read(buffer))) {
            output.write(buffer, 0, n);
        }

        ins.close();
        return output.toByteArray();
    } catch (IOException e) {
        throw new MetadataProviderException(e);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:27,代码来源:AbstractReloadingMetadataProvider.java

示例8: close

import java.io.InputStream; //导入方法依赖的package包/类
/**
 * Closes stream associated with current thread.
 *
 * @throws IOException if an error occurs
 */
@Override
public void close()
    throws IOException
{
    InputStream input = m_streams.get();
    if( null != input )
    {
        input.close();
    }
}
 
开发者ID:fesch,项目名称:Moenagade,代码行数:16,代码来源:DemuxInputStream.java

示例9: copyFile

import java.io.InputStream; //导入方法依赖的package包/类
private static void copyFile(File file, InputStream is, String mode)
        throws IOException, InterruptedException {
    final String abspath = file.getAbsolutePath();
    final FileOutputStream out = new FileOutputStream(file);
    byte buf[] = new byte[1024];
    int len;
    while ((len = is.read(buf)) > 0) {
        out.write(buf, 0, len);
    }

    out.close();
    is.close();

    Runtime.getRuntime().exec("chmod " + mode + " " + abspath).waitFor();
}
 
开发者ID:segasunset,项目名称:WeatherAlarmClock,代码行数:16,代码来源:AlarmClockService.java

示例10: testFileInputStream

import java.io.InputStream; //导入方法依赖的package包/类
@Test
public void testFileInputStream() throws IOException {
    InputStream is = new FileInputStream(file);
    assertFalse(is.markSupported());
    final String content = IOUtils.toString(is);
    final String content2 = IOUtils.toString(is);
    assertTrue(content.length() == 100);
    assertEquals(content2, "");
    is.close();
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:11,代码来源:ResettableInputStreamTest.java

示例11: copy

import java.io.InputStream; //导入方法依赖的package包/类
private int copy(InputStream in, RandomAccessFile out) throws IOException, UpdateError {

        byte[] buffer = new byte[BUFFER_SIZE];
        BufferedInputStream bis = new BufferedInputStream(in, BUFFER_SIZE);
        try {

            out.seek(out.length());

            int bytes = 0;
            long previousBlockTime = -1;

            while (!isCancelled()) {
                int n = bis.read(buffer, 0, BUFFER_SIZE);
                if (n == -1) {
                    break;
                }
                out.write(buffer, 0, n);
                bytes += n;

                checkNetwork();

                if (mSpeed != 0) {
                    previousBlockTime = -1;
                } else if (previousBlockTime == -1) {
                    previousBlockTime = System.currentTimeMillis();
                } else if ((System.currentTimeMillis() - previousBlockTime) > TIME_OUT) {
                    throw new UpdateError(UpdateError.DOWNLOAD_NETWORK_TIMEOUT);
                }
            }
            return bytes;
        } finally {
            out.close();
            bis.close();
            in.close();
        }
    }
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:37,代码来源:UpdateDownloader.java

示例12: copy

import java.io.InputStream; //导入方法依赖的package包/类
public static void copy(InputStream in, File file) {
	try {
		OutputStream out = new FileOutputStream(file);
		byte[] buf = new byte[1024];
		int len;
		while ((len = in.read(buf)) > 0) {
			out.write(buf, 0, len);
		}
		out.close();
		in.close();
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
开发者ID:thekeenant,项目名称:mczone,代码行数:15,代码来源:Files.java

示例13: addOTACert

import java.io.InputStream; //导入方法依赖的package包/类
/**
 * Add a copy of the public key to the archive; this should exactly match one
 * of the files in /system/etc/security/otacerts.zip on the device. (The same
 * cert can be extracted from the CERT.RSA file but this is much easier to get
 * at.)
 */
private static void addOTACert(
        JarOutputStream outputJar,
        long timestamp,
        Manifest manifest)
        throws IOException, GeneralSecurityException {
    InputStream input = new ByteArrayInputStream(readKeyContents(PUBLIC_KEY));
    
    BASE64Encoder base64 = new BASE64Encoder();
    MessageDigest md = MessageDigest.getInstance("SHA1");
    
    JarEntry je = new JarEntry(OTACERT_NAME);
    je.setTime(timestamp);
    outputJar.putNextEntry(je);
    
    byte[] b = new byte[4096];
    int read;
    
    System.out.print("\rGenerating OTA certificate...");
    
    while ((read = input.read(b)) != -1) {
        outputJar.write(b, 0, read);
        md.update(b, 0, read);
    }
    input.close();
    
    Attributes attr = new Attributes();
    attr.putValue("SHA1-Digest", base64.encode(md.digest()));
    manifest.getEntries().put(OTACERT_NAME, attr);
}
 
开发者ID:KuroroLucilfer,项目名称:PackageSigner2,代码行数:36,代码来源:Signer.java

示例14: getImageFromAssetsFile

import java.io.InputStream; //导入方法依赖的package包/类
private static Bitmap getImageFromAssetsFile(Context context,String fileName){
    Bitmap image = null;
    AssetManager am = context.getResources().getAssets();
    try{
        InputStream is = am.open(fileName);
        image = BitmapFactory.decodeStream(is);
        is.close();
    }catch (IOException e){
        e.printStackTrace();
    }
    return image;
}
 
开发者ID:TobiasLee,项目名称:FilterPlayer,代码行数:13,代码来源:OpenGlUtils.java

示例15: writeTo

import java.io.InputStream; //导入方法依赖的package包/类
public void writeTo(final OutputStream outstream) throws IOException {
    Args.notNull(outstream, "Output stream");
    final InputStream instream = new FileInputStream(this.file);
    try {
        final byte[] tmp = new byte[OUTPUT_BUFFER_SIZE];
        int l;
        while ((l = instream.read(tmp)) != -1) {
            outstream.write(tmp, 0, l);
        }
        outstream.flush();
    } finally {
        instream.close();
    }
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:15,代码来源:FileEntity.java


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