private static Object deserializeObject(File file) throws IOException, ClassNotFoundException { FileInputStream fileInputStream = null; ObjectInputStream objectInputStream = null; try { fileInputStream = new FileInputStream(file); objectInputStream = new ObjectInputStream(fileInputStream); return objectInputStream.readObject(); } finally { IOUtils.closeQuietly(objectInputStream); IOUtils.closeQuietly(fileInputStream); } }
private static void serializeObject(Object objectToSerialize, File file) throws IOException { FileOutputStream fileOutputStream = null; ObjectOutputStream objectOutputStream = null; try { fileOutputStream = new FileOutputStream(file); objectOutputStream = new ObjectOutputStream(fileOutputStream); objectOutputStream.writeObject(objectToSerialize); } finally { IOUtils.closeQuietly(objectOutputStream); IOUtils.closeQuietly(fileOutputStream); } }
@Override public synchronized TileBitmap get(Job key) { File file = this.findFile(key); if (file == null) { return null; } InputStream inputStream = null; try { inputStream = new FileInputStream(file); return this.graphicFactory.createTileBitmap(inputStream, key.tile.tileSize, key.hasAlpha); } catch (CorruptedInputStreamException e) { // this can happen, at least on Android, when the input stream // is somehow corrupted, returning null ensures it will be loaded // from another source return null; } catch (IOException e) { return null; } finally { IOUtils.closeQuietly(inputStream); } }
@Test public void closeQuietlyTest() { IOUtils.closeQuietly(null); DummyCloseable dummyCloseable = new DummyCloseable(); IOUtils.closeQuietly(dummyCloseable); Assert.assertTrue(dummyCloseable.closed); IOUtils.closeQuietly(dummyCloseable); } }
return null; } finally { IOUtils.closeQuietly(inputStream);
protected final void addFile(String path, File file) throws IOException { File fileCopy = new File(this.httpRoot, path); Assert.assertFalse(fileCopy.exists()); if (!fileCopy.getParentFile().exists()) { Assert.assertTrue(fileCopy.getParentFile().mkdirs()); } OutputStream outputStream = new FileOutputStream(fileCopy); try { outputStream.write(FileUtils.readFileToByteArray(file)); } finally { IOUtils.closeQuietly(outputStream); } }
IOUtils.closeQuietly(outputStream);
public static RenderTheme getRenderTheme(GraphicFactory graphicFactory, DisplayModel displayModel, XmlRenderTheme xmlRenderTheme) throws IOException, XmlPullParserException { XmlPullParser pullParser = getXmlPullParserFactory().newPullParser(); RenderThemeHandler renderThemeHandler = new RenderThemeHandler(graphicFactory, displayModel, xmlRenderTheme.getRelativePathPrefix(), xmlRenderTheme, pullParser); InputStream inputStream = null; try { inputStream = xmlRenderTheme.getRenderThemeAsStream(); pullParser.setInput(inputStream, null); renderThemeHandler.processRenderTheme(); return renderThemeHandler.renderTheme; } finally { IOUtils.closeQuietly(inputStream); } }
IOUtils.closeQuietly(inputStream);
@Override public void run() { String fileName = createFileName(this.hash); FileOutputStream outputStream = null; try { outputStream = AndroidGraphicFactory.INSTANCE.openFileOutput(fileName, Context.MODE_PRIVATE); if (!this.bitmap.compress(Bitmap.CompressFormat.PNG, 0, outputStream)) { LOGGER.warning("SVG Failed to write svg bitmap " + fileName); } } catch (IllegalStateException e) { LOGGER.warning("SVG Failed to stream bitmap to file " + fileName); } catch (FileNotFoundException e) { LOGGER.warning("SVG Failed to create file for svg bitmap " + fileName); } finally { IOUtils.closeQuietly(outputStream); } } }
public static Bitmap get(int hash) { String fileName = createFileName(hash); FileInputStream inputStream = null; try { inputStream = AndroidGraphicFactory.INSTANCE.openFileInput(fileName); return BitmapFactory.decodeStream(inputStream); } catch (FileNotFoundException e) { // ignore: file is not yet in cache } finally { IOUtils.closeQuietly(inputStream); } return null; }
@Override public synchronized TileBitmap get(Job key) { File file = this.findFile(key); if (file == null) { return null; } InputStream inputStream = null; try { inputStream = new FileInputStream(file); return this.graphicFactory.createTileBitmap(inputStream, key.tile.tileSize, key.hasAlpha); } catch (CorruptedInputStreamException e) { // this can happen, at least on Android, when the input stream // is somehow corrupted, returning null ensures it will be loaded // from another source return null; } catch (IOException e) { return null; } finally { IOUtils.closeQuietly(inputStream); } }
AndroidTileBitmap(InputStream inputStream, int tileSize, boolean isTransparent) { super(); try { if (AndroidGraphicFactory.DEBUG_BITMAPS) { tileInstances.incrementAndGet(); } this.bitmap = BitmapFactory.decodeStream(inputStream, null, createTileBitmapFactoryOptions(tileSize, isTransparent)); // somehow on Android the decode stream can succeed, but the bitmap remains invalid. // Asking for the width forces the bitmap to be fully loaded and a NullPointerException // is triggered if the stream is not readable, // so that it can be handled at this point, rather than later // during bitmap painting this.bitmap.getWidth(); //NOSONAR } catch (Exception e) { // this is really stupid, the runtime system actually throws a SocketTimeoutException, // but we cannot catch it, because it is not declared, so we needed to catch the base // class exception LOGGER.info("TILEBITMAP ERROR " + e.toString()); this.bitmap = null; // need to null out to avoid recycling IOUtils.closeQuietly(inputStream); // seems to improve memory usage this.destroy(); throw new CorruptedInputStreamException("Corrupted bitmap input stream", e); } }
return null; } finally { IOUtils.closeQuietly(inputStream);
IOUtils.closeQuietly(outputStream);
public static RenderTheme getRenderTheme(GraphicFactory graphicFactory, DisplayModel displayModel, XmlRenderTheme xmlRenderTheme) throws IOException, XmlPullParserException { XmlPullParser pullParser = getXmlPullParserFactory().newPullParser(); RenderThemeHandler renderThemeHandler = new RenderThemeHandler(graphicFactory, displayModel, xmlRenderTheme.getRelativePathPrefix(), xmlRenderTheme, pullParser); InputStream inputStream = null; try { inputStream = xmlRenderTheme.getRenderThemeAsStream(); pullParser.setInput(inputStream, null); renderThemeHandler.processRenderTheme(); return renderThemeHandler.renderTheme; } finally { IOUtils.closeQuietly(inputStream); } }
IOUtils.closeQuietly(inputStream);