Tabnine Logo
InputStream.close
Code IndexAdd Tabnine to your IDE (free)

How to use
close
method
in
java.io.InputStream

Best Java code snippets using java.io.InputStream.close (Showing top 20 results out of 99,180)

Refine searchRefine arrow

  • InputStream.read
  • OutputStream.write
  • FileOutputStream.<init>
  • OutputStream.close
  • FileInputStream.<init>
  • File.<init>
origin: stackoverflow.com

 InputStream in;
OutputStream out;
IOUtils.copy(in,out);
in.close();
out.close();
origin: stackoverflow.com

 public void copy(File src, File dst) throws IOException {
  InputStream in = new FileInputStream(src);
  OutputStream out = new FileOutputStream(dst);

  // Transfer bytes from in to out
  byte[] buf = new byte[1024];
  int len;
  while ((len = in.read(buf)) > 0) {
    out.write(buf, 0, len);
  }
  in.close();
  out.close();
}
origin: bumptech/glide

public static byte[] isToBytes(InputStream is) throws IOException {
 ByteArrayOutputStream os = new ByteArrayOutputStream();
 byte[] buffer = new byte[1024];
 int read;
 try {
  while ((read = is.read(buffer)) != -1) {
   os.write(buffer, 0, read);
  }
 } finally {
  is.close();
 }
 return os.toByteArray();
}
origin: stackoverflow.com

File f = new File(getCacheDir()+"/m1.map");
if (!f.exists()) try {
 InputStream is = getAssets().open("m1.map");
 int size = is.available();
 byte[] buffer = new byte[size];
 is.read(buffer);
 is.close();
 FileOutputStream fos = new FileOutputStream(f);
 fos.write(buffer);
 fos.close();
} catch (Exception e) { throw new RuntimeException(e); }
mapView.setMapFile(f.getPath());
origin: iBotPeaches/Apktool

public static void cpdir(File src, File dest) throws BrutException {
  dest.mkdirs();
  File[] files = src.listFiles();
  for (int i = 0; i < files.length; i++) {
    File file = files[i];
    File destFile = new File(dest.getPath() + File.separatorChar
      + file.getName());
    if (file.isDirectory()) {
      cpdir(file, destFile);
      continue;
    }
    try {
      InputStream in = new FileInputStream(file);
      OutputStream out = new FileOutputStream(destFile);
      IOUtils.copy(in, out);
      in.close();
      out.close();
    } catch (IOException ex) {
      throw new BrutException("Could not copy file: " + file, ex);
    }
  }
}
origin: apache/zookeeper

  @Override
  public void write(OutputStream output) throws IOException {
    InputStream input = null;
    try {
      input = new FileInputStream(new File(configFileStr));
      byte[] buf = new byte[1024];
      int bytesRead;
      while ((bytesRead = input.read(buf)) > 0) {
        output.write(buf, 0, bytesRead);
      }
    } finally {
      if( input != null) {
        input.close();
      }
    }
  }
});
origin: apache/incubator-dubbo

/**
 * get md5.
 *
 * @param file file source.
 * @return MD5 byte array.
 */
public static byte[] getMD5(File file) throws IOException {
  InputStream is = new FileInputStream(file);
  try {
    return getMD5(is);
  } finally {
    is.close();
  }
}
origin: redisson/redisson

/**
 * {@inheritDoc}
 */
public Manifest getManifest() throws IOException {
  File file = new File(folder, JarFile.MANIFEST_NAME);
  if (file.exists()) {
    InputStream inputStream = new FileInputStream(file);
    try {
      return new Manifest(inputStream);
    } finally {
      inputStream.close();
    }
  } else {
    return NO_MANIFEST;
  }
}
origin: commonsguy/cw-omnibus

 static private void copy(InputStream in, File dst) throws IOException {
  FileOutputStream out=new FileOutputStream(dst);
  byte[] buf=new byte[1024];
  int len;

  while ((len=in.read(buf)) > 0) {
   out.write(buf, 0, len);
  }

  in.close();
  out.close();
 }
}
origin: pxb1988/dex2jar

public static byte[] readFile(File in) throws IOException {
  InputStream is = new FileInputStream(in);
  byte[] xml = new byte[is.available()];
  is.read(xml);
  is.close();
  return xml;
}
origin: hs-web/hsweb-framework

@Override
public String saveStaticFile(InputStream fileStream, String fileName) throws IOException {
  try {
    //文件后缀
    String suffix = fileName.contains(".") ?
        fileName.substring(fileName.lastIndexOf(".")) : "";
    //以日期划分目录
    String filePath = DateFormatter.toString(new Date(), "yyyyMMdd");
    //创建目录
    new File(getStaticFilePath() + "/" + filePath).mkdirs();
    // 存储的文件名
    String realFileName = System.nanoTime() + suffix;
    String fileAbsName = getStaticFilePath() + "/" + filePath + "/" + realFileName;
    try (FileOutputStream out = new FileOutputStream(fileAbsName)) {
      StreamUtils.copy(fileStream, out);
    }
    //响应上传成功的资源信息
    return getStaticLocation() + filePath + "/" + realFileName;
  } finally {
    fileStream.close();
  }
}
origin: Tencent/tinker

private void addTestDex() throws IOException {
  //write test dex
  String dexMode = "jar";
  if (config.mDexRaw) {
    dexMode = "raw";
  }
  final InputStream is = DexDiffDecoder.class.getResourceAsStream("/" + TEST_DEX_NAME);
  String md5 = MD5.getMD5(is, 1024);
  is.close();
  String meta = TEST_DEX_NAME + "," + "" + "," + md5 + "," + md5 + "," + 0 + "," + 0 + "," + 0 + "," + dexMode;
  File dest = new File(config.mTempResultDir + "/" + TEST_DEX_NAME);
  FileOperation.copyResourceUsingStream(TEST_DEX_NAME, dest);
  Logger.d("\nAdd test install result dex: %s, size:%d", dest.getAbsolutePath(), dest.length());
  Logger.d("DexDecoder:write test dex meta file data: %s", meta);
  metaWriter.writeLineToInfoFile(meta);
}
origin: robolectric/robolectric

public static void copy(InputStream in, OutputStream out) throws IOException {
 byte[] buffer = new byte[8196];
 int len;
 try {
  while ((len = in.read(buffer)) != -1) {
   out.write(buffer, 0, len);
  }
 } finally {
  in.close();
 }
}
origin: iBotPeaches/Apktool

  public static File extractToTmp(String resourcePath, String tmpPrefix, Class clazz) throws BrutException {
    try {
      InputStream in = clazz.getResourceAsStream(resourcePath);
      if (in == null) {
        throw new FileNotFoundException(resourcePath);
      }
      File fileOut = File.createTempFile(tmpPrefix, null);
      fileOut.deleteOnExit();
      OutputStream out = new FileOutputStream(fileOut);
      IOUtils.copy(in, out);
      in.close();
      out.close();
      return fileOut;
    } catch (IOException ex) {
      throw new BrutException("Could not extract resource: " + resourcePath, ex);
    }
  }
}
origin: jenkinsci/jenkins

  @Override
  public void run() {
    try {
      try {
        byte[] buf = new byte[8192];
        int len;
        while ((len = in.read(buf)) >= 0)
          out.write(buf, 0, len);
      } finally {
        // it doesn't make sense not to close InputStream that's already EOF-ed,
        // so there's no 'closeIn' flag.
        in.close();
        if(closeOut)
          out.close();
      }
    } catch (IOException e) {
      // TODO: what to do?
    }
  }
}
origin: stackoverflow.com

 InputStream is = entity.getContent();
String filePath = "sample.txt";
FileOutputStream fos = new FileOutputStream(new File(filePath));
int inByte;
while((inByte = is.read()) != -1)
   fos.write(inByte);
is.close();
fos.close();
origin: prestodb/presto

private void writeZone(File outputDir, DateTimeZoneBuilder builder, DateTimeZone tz) throws IOException {
  if (ZoneInfoLogger.verbose()) {
    System.out.println("Writing " + tz.getID());
  }
  File file = new File(outputDir, tz.getID());
  if (!file.getParentFile().exists()) {
    file.getParentFile().mkdirs();
  }
  OutputStream out = new FileOutputStream(file);
  try {
    builder.writeTo(tz.getID(), out);
  } finally {
    out.close();
  }
  // Test if it can be read back.
  InputStream in = new FileInputStream(file);
  DateTimeZone tz2 = DateTimeZoneBuilder.readFrom(in, tz.getID());
  in.close();
  if (!tz.equals(tz2)) {
    System.out.println("*e* Error in " + tz.getID() +
              ": Didn't read properly from file");
  }
}
origin: google/guava

private static void skipHelper(long n, int expect, InputStream in) throws IOException {
 ByteStreams.skipFully(in, n);
 assertEquals(expect, in.read());
 in.close();
}
origin: apache/incubator-dubbo

/**
 * get md5.
 *
 * @param file file source.
 * @return MD5 byte array.
 */
public static byte[] getMD5(File file) throws IOException {
  InputStream is = new FileInputStream(file);
  try {
    return getMD5(is);
  } finally {
    is.close();
  }
}
origin: redisson/redisson

/**
 * {@inheritDoc}
 */
public Resolution locate(String name) throws IOException {
  File file = new File(folder, name.replace('.', File.separatorChar) + CLASS_FILE_EXTENSION);
  if (file.exists()) {
    InputStream inputStream = new FileInputStream(file);
    try {
      return new Resolution.Explicit(StreamDrainer.DEFAULT.drain(inputStream));
    } finally {
      inputStream.close();
    }
  } else {
    return new Resolution.Illegal(name);
  }
}
java.ioInputStreamclose

Javadoc

Closes this stream. Concrete implementations of this class should free any resources during close. This implementation does nothing.

Popular methods of InputStream

  • read
    Reads up to len bytes of data from the input stream into an array of bytes. An attempt is made to re
  • available
    Returns the number of bytes that can be read (or skipped over) from this input stream without blocki
  • skip
    Skips over and discards n bytes of data from this input stream. The skip method may, for a variety o
  • reset
    Repositions this stream to the position at the time themark method was last called on this input str
  • mark
    Marks the current position in this input stream. A subsequent call to the reset method repositions
  • markSupported
    Tests if this input stream supports the mark andreset methods. Whether or not mark andreset are sup
  • transferTo
  • <init>
    This constructor does nothing. It is provided for signature compatibility.
  • readAllBytes
  • readNBytes

Popular in Java

  • Reading from database using SQL prepared statement
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • getApplicationContext (Context)
  • compareTo (BigDecimal)
  • SecureRandom (java.security)
    This class generates cryptographically secure pseudo-random numbers. It is best to invoke SecureRand
  • Calendar (java.util)
    Calendar is an abstract base class for converting between a Date object and a set of integer fields
  • Hashtable (java.util)
    A plug-in replacement for JDK1.5 java.util.Hashtable. This version is based on org.cliffc.high_scale
  • Callable (java.util.concurrent)
    A task that returns a result and may throw an exception. Implementors define a single method with no
  • Notification (javax.management)
  • Get (org.apache.hadoop.hbase.client)
    Used to perform Get operations on a single row. To get everything for a row, instantiate a Get objec
  • From CI to AI: The AI layer in your organization
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now