Example usage for java.io ByteArrayInputStream close

List of usage examples for java.io ByteArrayInputStream close

Introduction

In this page you can find the example usage for java.io ByteArrayInputStream close.

Prototype

public void close() throws IOException 

Source Link

Document

Closing a ByteArrayInputStream has no effect.

Usage

From source file:org.shareok.data.webserv.JournalDataController.java

@RequestMapping(value = "/dspace/safpackage/doi/generate", method = RequestMethod.POST)
public ModelAndView safPackageGenerateByDois(HttpServletRequest request, RedirectAttributes redirectAttrs,
        @RequestParam(value = "multiDoiUploadFile", required = false) MultipartFile file) {
    String singleDoi = (String) request.getParameter("singleDoi");
    String multiDoi = (String) request.getParameter("multiDoi");
    String safPaths = null;/*from   w w  w  .j av a  2  s .c  o m*/
    ByteArrayInputStream stream = null;

    ModelAndView model = new ModelAndView();
    RedirectView view = new RedirectView();
    view.setContextRelative(true);

    if ((null != file && !file.isEmpty()) || null != singleDoi || null != multiDoi) {
        String safFilePath = null;
        try {
            String[] dois;
            if (null != singleDoi) {
                String doi = (String) request.getParameter("doiInput");
                if (null == doi || doi.equals("")) {
                    throw new EmptyDoiInformationException("Empty information from single DOI submission!");
                }
                dois = new String[] { doi };
            } else if (null != multiDoi) {
                String doi = (String) request.getParameter("multiDoiInput");
                if (null == doi || doi.equals("")) {
                    throw new EmptyDoiInformationException("Empty information from multiple DOI submission!");
                }
                dois = doi.trim().split("\\s*;\\s*");
            } else if (null != file && !file.isEmpty()) {
                stream = new ByteArrayInputStream(file.getBytes());
                String doiString = IOUtils.toString(stream, "UTF-8");
                dois = doiString.trim().split("\\s*\\r?\\n\\s*");
            } else {
                throw new EmptyDoiInformationException("Empty DOI information from unknown DOI submission!");
            }
            if (dois != null && dois.length > 0) {

            }
        } catch (Exception ex) {
            logger.error("Cannot generate the SAF packages by the DOIs", ex);
        } finally {
            if (null != stream) {
                try {
                    stream.close();
                } catch (IOException ex) {
                    logger.error("Cannot close the input stream when reading the file containing the DOIs", ex);
                }
            }
        }
        if (null != safFilePath && !safFilePath.equals("")) {
            redirectAttrs.addFlashAttribute("safFilePath", safFilePath);
            view.setUrl(".jsp");
            model.setView(view);
        } else {
            redirectAttrs.addFlashAttribute("errorMessage", "The saf file path is invalid");
            view.setUrl("journalDataUpload.jsp");
            model.setView(view);
        }
    } else {
        redirectAttrs.addFlashAttribute("errorMessage", "The server information is empty");
        view.setUrl("errors/serverError.jsp");
        model.setView(view);
    }
    return model;
}

From source file:net.geoprism.dashboard.DashboardMap.java

private BufferedImage getImageFromGeoserver(String _requestURL) {
    for (int i = 0; i < 10; i++) {
        // Make the getMap or getLegendGraphic request to geoserver for this layer
        // and return a byte[] of the returned image
        byte[] response = this.requestGeoserverImage(_requestURL);

        ByteArrayInputStream istream = new ByteArrayInputStream(response);

        try {//  ww  w . j  a va 2 s  . c  o m
            // Convert the response into an image.
            // Note that the reponse may not be a valid image
            // If this is the case then ImageIO.read will return
            // a null BufferedImage.
            BufferedImage image = ImageIO.read(istream);

            if (image != null) {
                return image;
            } else {
                // Wait a couple seconds and try again
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    // Do nothing
                }
            }
        } catch (IOException e) {
            String error = "Could not read the map request image from the map server.";
            throw new ProgrammingErrorException(error, e);
        } finally {
            try {
                istream.close();
            } catch (IOException e) {
                String error = "Could not close stream.";
                throw new ProgrammingErrorException(error, e);
            }
        }
    }

    throw new ProgrammingErrorException("Error creating layers image");
}

From source file:org.jlibrary.core.jcr.JCRRepositoryService.java

public Node updateContent(Ticket ticket, String nodeId, byte[] content)
        throws SecurityException, RepositoryException {

    ByteArrayInputStream bais = null;
    try {//w  w w . jav  a 2 s. co m
        bais = new ByteArrayInputStream(content);
        Node updatedNode = updateContent(ticket, nodeId, bais);
        return updatedNode;
    } finally {
        try {
            if (bais != null) {
                bais.close();
            }
        } catch (IOException e) {
            logger.error(e.getMessage(), e);
            throw new RepositoryException(e);
        }
    }

}

From source file:org.gbif.harvest.tapir.TapirMetadataHandler.java

/**
 * Parse the search response for the record count.
 *
 * @param inputStream    search response as ByteArrayInputStream
 * @param itemOfInterest XPath to namespace element
 *
 * @return count// ww w.j a v  a 2 s.  c  om
 *
 * @throws IOException  thrown
 * @throws SAXException thrown
 */
private String returnCount(ByteArrayInputStream inputStream, String itemOfInterest)
        throws IOException, SAXException {

    List<String> records = new LinkedList<String>();
    Digester digester = new Digester();
    digester.setNamespaceAware(true);
    digester.push(records);
    if (itemOfInterest.contains("@")) {
        String[] parts = itemOfInterest.split("@");
        digester.addCallMethod(parts[0], "add", 1);
        // digester.addObjectParam(parts[0], 0, parts[0] + "@" + parts[1]);
        digester.addCallParam(parts[0], 0, parts[1]);
    } else {
        digester.addCallMethod(itemOfInterest, "add", 1);
        // digester.addObjectParam(itemOfInterest, 0, itemOfInterest);
        digester.addCallParam(itemOfInterest, 0);
    }
    digester.parse(inputStream);

    // close inputStream
    try {
        if (inputStream != null) {
            inputStream.close();
        }
    } catch (Exception e) {
        // do nothing
    }

    if (records.size() != 1) {
        return "0";
    }

    return records.get(0);
}

From source file:com.knowgate.dfs.FileSystem.java

/**
 * Detect file encoding//from   w ww.  j av  a 2  s  .com
 * @param sFilePath File Path including protocol. Like "file:///tmp/myfile.txt" or "ftp://myhost:21/dir/myfile.txt"
 * @param sDefault String Character encoding to be returned if no clear character encoding was identified
 * @return String UTF-16LE, UTF-16BE or UTF-8
 * @throws FileNotFoundException
 * @throws IOException
 * @since 3.1
 */
public String detectEncoding(String sFilePath, String sDefault)
        throws FileNotFoundException, IOException, FTPException {
    byte[] byBuffer = readfilebin(sFilePath);
    if (null == byBuffer)
        return sDefault;
    if (byBuffer.length == 0)
        return sDefault;
    ByteArrayInputStream oInStrm = new ByteArrayInputStream(readfilebin(sFilePath));
    String sEncoding = new CharacterSetDetector().detect(oInStrm, sDefault);
    oInStrm.close();
    return sEncoding;
}

From source file:javazoom.jlgui.player.amp.skin.Skin.java

/**
 * Instantiate playlist panel./*from www. jav a  2 s.co  m*/
 */
public void setPlaylistPanel() {
    playlist = new PlaylistUIDelegate();
    Image titleCenter = new BufferedImage(100, 20, BufferedImage.TYPE_INT_RGB);
    titleCenter.getGraphics().drawImage(imPlaylist, 0, 0, 100, 20, 26, 0, 126, 20, null);
    playlist.setTitleCenterImage(titleCenter);
    Image titleLeft = new BufferedImage(25, 20, BufferedImage.TYPE_INT_RGB);
    titleLeft.getGraphics().drawImage(imPlaylist, 0, 0, 25, 20, 0, 0, 25, 20, null);
    playlist.setTitleLeftImage(titleLeft);
    Image titleStretch = new BufferedImage(25, 20, BufferedImage.TYPE_INT_RGB);
    titleStretch.getGraphics().drawImage(imPlaylist, 0, 0, 25, 20, 127, 0, 152, 20, null);
    playlist.setTitleStretchImage(titleStretch);
    Image titleRight = new BufferedImage(25, 20, BufferedImage.TYPE_INT_RGB);
    titleRight.getGraphics().drawImage(imPlaylist, 0, 0, 25, 20, 153, 0, 178, 20, null);
    playlist.setTitleRightImage(titleRight);
    Image btmLeft = new BufferedImage(125, 38, BufferedImage.TYPE_INT_RGB);
    btmLeft.getGraphics().drawImage(imPlaylist, 0, 0, 125, 38, 0, 72, 125, 110, null);
    playlist.setBottomLeftImage(btmLeft);
    Image btmRight = new BufferedImage(150, 38, BufferedImage.TYPE_INT_RGB);
    btmRight.getGraphics().drawImage(imPlaylist, 0, 0, 150, 38, 126, 72, 276, 110, null);
    playlist.setBottomRightImage(btmRight);
    Image bodyLeft = new BufferedImage(12, 28, BufferedImage.TYPE_INT_RGB);
    bodyLeft.getGraphics().drawImage(imPlaylist, 0, 0, 12, 28, 0, 42, 12, 70, null);
    playlist.setLeftImage(bodyLeft);
    Image bodyRight = new BufferedImage(20, 28, BufferedImage.TYPE_INT_RGB);
    bodyRight.getGraphics().drawImage(imPlaylist, 0, 0, 20, 28, 31, 42, 51, 70, null);
    playlist.setRightImage(bodyRight);
    // Parse color
    plEdit = plEdit.toLowerCase();
    ByteArrayInputStream in = new ByteArrayInputStream(plEdit.getBytes());
    BufferedReader lin = new BufferedReader(new InputStreamReader(in));
    try {
        for (;;) {
            String line = lin.readLine();
            if (line == null)
                break;
            if ((line.toLowerCase()).startsWith("normalbg"))
                playlist.setBackgroundColor(parsePlEditColor(line));
            else if ((line.toLowerCase()).startsWith("normal"))
                playlist.setNormalColor(parsePlEditColor(line));
            else if ((line.toLowerCase()).startsWith("current"))
                playlist.setCurrentColor(parsePlEditColor(line));
            else if ((line.toLowerCase()).startsWith("selectedbg"))
                playlist.setSelectedBackgroundColor(parsePlEditColor(line));
        }
    } catch (Exception e) {
        log.debug(e);
    } finally {
        try {
            if (in != null)
                in.close();
        } catch (IOException e) {
        }
    }
    // Playlist slider.
    acPlSlider = new ActiveJSlider();
    acPlSlider.setOrientation(JSlider.VERTICAL);
    acPlSlider.setMinimum(0);
    acPlSlider.setMaximum(100);
    acPlSlider.setValue(100);
    ActiveSliderUI sUI = new ActiveSliderUI(acPlSlider);
    Image scrollBarReleased = new BufferedImage(8, 18, BufferedImage.TYPE_INT_RGB);
    scrollBarReleased.getGraphics().drawImage(imPlaylist, 0, 0, 8, 18, 52, 53, 52 + 8, 53 + 18, null);
    sUI.setThumbImage(scrollBarReleased);
    Image scrollBarClicked = new BufferedImage(8, 18, BufferedImage.TYPE_INT_RGB);
    scrollBarClicked.getGraphics().drawImage(imPlaylist, 0, 0, 8, 18, 61, 53, 61 + 8, 53 + 18, null);
    sUI.setThumbPressedImage(scrollBarClicked);
    Image sliderBackground = new BufferedImage(20, 58, BufferedImage.TYPE_INT_RGB);
    sliderBackground.getGraphics().drawImage(bodyRight, 0, 0, null);
    sliderBackground.getGraphics().drawImage(bodyRight, 0, 28, null);
    sliderBackground.getGraphics().drawImage(bodyRight, 0, 30, null);
    Image[] background = { sliderBackground };
    sUI.setBackgroundImages(background);
    sUI.setThumbXOffset(5);
    acPlSlider.setUI(sUI);
    acPlSlider.setConstraints(new AbsoluteConstraints(plSliderLocation[0], plSliderLocation[1], 20, 58));
    // Up/Down scroll buttons
    acPlUp = new ActiveJButton();
    Image upScrollButton = new BufferedImage(8, 4, BufferedImage.TYPE_INT_RGB);
    upScrollButton.getGraphics().drawImage(imPlaylist, 0, 0, 8, 4, 261, 75, 269, 79, null);
    acPlUp.setIcon(new ImageIcon(upScrollButton));
    acPlUp.setPressedIcon(new ImageIcon(upScrollButton));
    acPlUp.setConstraints(new AbsoluteConstraints(WinWidth - 15, WinHeight - 35, 8, 4));
    acPlUp.setActionCommand(PlayerActionEvent.ACPLUP);
    acPlDown = new ActiveJButton();
    Image downScrollButton = new BufferedImage(8, 4, BufferedImage.TYPE_INT_RGB);
    downScrollButton.getGraphics().drawImage(imPlaylist, 0, 0, 8, 4, 261, 80, 269, 84, null);
    acPlDown.setIcon(new ImageIcon(downScrollButton));
    acPlDown.setPressedIcon(new ImageIcon(downScrollButton));
    acPlDown.setConstraints(new AbsoluteConstraints(WinWidth - 15, WinHeight - 30, 8, 4));
    acPlDown.setActionCommand(PlayerActionEvent.ACPLDOWN);
    // Playlist AddFile/AddDir/AddURL buttons
    int w = 22;
    int h = 18;
    Image addButtonImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    addButtonImage.getGraphics().drawImage(imPlaylist, 0, 0, w, h, 14, 80, 14 + w, 80 + h, null);
    acPlAdd = new ActiveJButton();
    acPlAdd.setIcon(new ImageIcon(addButtonImage));
    acPlAdd.setPressedIcon(new ImageIcon(addButtonImage));
    acPlAdd.setActionCommand(PlayerActionEvent.ACPLADDPOPUP);
    acPlAdd.setConstraints(new AbsoluteConstraints(plAddLocation[0], plAddLocation[1], w, h));
    ActiveJButton acPlAddFile = createPLButton(0, 149);
    acPlAddFile.setActionCommand(PlayerActionEvent.ACPLADDFILE);
    ActiveJButton acPlAddDir = createPLButton(0, 130);
    acPlAddDir.setActionCommand(PlayerActionEvent.ACPLADDDIR);
    ActiveJButton acPlAddURL = createPLButton(0, 111);
    acPlAddURL.setActionCommand(PlayerActionEvent.ACPLADDURL);
    acPlAddPopup = new ActiveJPopup();
    ActiveJButton[] addbuttons = { acPlAddURL, acPlAddDir, acPlAddFile };
    acPlAddPopup.setItems(addbuttons);
    acPlAddPopup.setConstraints(new AbsoluteConstraints(plAddPopupArea[0], plAddPopupArea[1], plAddPopupArea[2],
            plAddPopupArea[3]));
    // Playlist RemoveMisc/RemoveSelection/Crop/RemoveAll buttons
    Image removeButtonImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    removeButtonImage.getGraphics().drawImage(imPlaylist, 0, 0, w, h, 14 + 30, 80, 14 + 30 + w, 80 + h, null);
    acPlRemove = new ActiveJButton();
    acPlRemove.setIcon(new ImageIcon(removeButtonImage));
    acPlRemove.setPressedIcon(new ImageIcon(removeButtonImage));
    acPlRemove.setActionCommand(PlayerActionEvent.ACPLREMOVEPOPUP);
    acPlRemove.setConstraints(new AbsoluteConstraints(plRemoveLocation[0], plRemoveLocation[1], w, h));
    ActiveJButton acPlRemoveMisc = createPLButton(54, 168);
    acPlRemoveMisc.setActionCommand(PlayerActionEvent.ACPLREMOVEMISC);
    ActiveJButton acPlRemoveSel = createPLButton(54, 149);
    acPlRemoveSel.setActionCommand(PlayerActionEvent.ACPLREMOVESEL);
    ActiveJButton acPlRemoveCrop = createPLButton(54, 130);
    acPlRemoveCrop.setActionCommand(PlayerActionEvent.ACPLREMOVECROP);
    ActiveJButton acPlRemoveAll = createPLButton(54, 111);
    acPlRemoveAll.setActionCommand(PlayerActionEvent.ACPLREMOVEALL);
    acPlRemovePopup = new ActiveJPopup();
    ActiveJButton[] rembuttons = { acPlRemoveMisc, acPlRemoveAll, acPlRemoveCrop, acPlRemoveSel };
    acPlRemovePopup.setItems(rembuttons);
    acPlRemovePopup.setConstraints(new AbsoluteConstraints(plRemovePopupArea[0], plRemovePopupArea[1],
            plRemovePopupArea[2], plRemovePopupArea[3]));
    // Playlist SelAll/SelZero/SelInv buttons
    Image selButtonImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    selButtonImage.getGraphics().drawImage(imPlaylist, 0, 0, w, h, 14 + 60, 80, 14 + 60 + w, 80 + h, null);
    acPlSelect = new ActiveJButton();
    acPlSelect.setIcon(new ImageIcon(selButtonImage));
    acPlSelect.setPressedIcon(new ImageIcon(selButtonImage));
    acPlSelect.setActionCommand(PlayerActionEvent.ACPLSELPOPUP);
    acPlSelect.setConstraints(new AbsoluteConstraints(plSelectLocation[0], plSelectLocation[1], w, h));
    ActiveJButton acPlSelectAll = createPLButton(104, 149);
    acPlSelectAll.setActionCommand(PlayerActionEvent.ACPLSELALL);
    ActiveJButton acPlSelectZero = createPLButton(104, 130);
    acPlSelectZero.setActionCommand(PlayerActionEvent.ACPLSELZERO);
    ActiveJButton acPlSelectInv = createPLButton(104, 111);
    acPlSelectInv.setActionCommand(PlayerActionEvent.ACPLSELINV);
    acPlSelectPopup = new ActiveJPopup();
    ActiveJButton[] selbuttons = { acPlSelectInv, acPlSelectZero, acPlSelectAll };
    acPlSelectPopup.setItems(selbuttons);
    acPlSelectPopup.setConstraints(new AbsoluteConstraints(plSelectPopupArea[0], plSelectPopupArea[1],
            plSelectPopupArea[2], plSelectPopupArea[3]));
    // Playlist MiscOpts/MiscFile/MiscSort buttons
    Image miscButtonImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    miscButtonImage.getGraphics().drawImage(imPlaylist, 0, 0, w, h, 14 + 89, 80, 14 + 89 + w, 80 + h, null);
    acPlMisc = new ActiveJButton();
    acPlMisc.setIcon(new ImageIcon(miscButtonImage));
    acPlMisc.setPressedIcon(new ImageIcon(miscButtonImage));
    acPlMisc.setActionCommand(PlayerActionEvent.ACPLMISCPOPUP);
    acPlMisc.setConstraints(new AbsoluteConstraints(plMiscLocation[0], plMiscLocation[1], w, h));
    ActiveJButton acPlMiscOpts = createPLButton(154, 149);
    acPlMiscOpts.setActionCommand(PlayerActionEvent.ACPLMISCOPTS);
    ActiveJButton acPlMiscFile = createPLButton(154, 130);
    acPlMiscFile.setActionCommand(PlayerActionEvent.ACPLMISCFILE);
    ActiveJButton acPlMiscSort = createPLButton(154, 111);
    acPlMiscSort.setActionCommand(PlayerActionEvent.ACPLMISCSORT);
    acPlMiscPopup = new ActiveJPopup();
    ActiveJButton[] miscbuttons = { acPlMiscSort, acPlMiscFile, acPlMiscOpts };
    acPlMiscPopup.setItems(miscbuttons);
    acPlMiscPopup.setConstraints(new AbsoluteConstraints(plMiscPopupArea[0], plMiscPopupArea[1],
            plMiscPopupArea[2], plMiscPopupArea[3]));
    // Playlist ListLoad/ListSave/ListNew buttons
    Image listButtonImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    listButtonImage.getGraphics().drawImage(imPlaylist, 0, 0, w, h, 14 + 215, 80, 14 + 215 + w, 80 + h, null);
    acPlList = new ActiveJButton();
    acPlList.setIcon(new ImageIcon(listButtonImage));
    acPlList.setPressedIcon(new ImageIcon(listButtonImage));
    acPlList.setActionCommand(PlayerActionEvent.ACPLLISTPOPUP);
    acPlList.setConstraints(new AbsoluteConstraints(plListLocation[0], plListLocation[1], w, h));
    ActiveJButton acPlListLoad = createPLButton(204, 149);
    acPlListLoad.setActionCommand(PlayerActionEvent.ACPLLISTLOAD);
    ActiveJButton acPlListSave = createPLButton(204, 130);
    acPlListSave.setActionCommand(PlayerActionEvent.ACPLLISTSAVE);
    ActiveJButton acPlListNew = createPLButton(204, 111);
    acPlListNew.setActionCommand(PlayerActionEvent.ACPLLISTNEW);
    acPlListPopup = new ActiveJPopup();
    ActiveJButton[] listbuttons = { acPlListNew, acPlListSave, acPlListLoad };
    acPlListPopup.setItems(listbuttons);
    acPlListPopup.setConstraints(new AbsoluteConstraints(plListPopupArea[0], plListPopupArea[1],
            plListPopupArea[2], plListPopupArea[3]));
}

From source file:csic.ceab.movelab.beepath.Util.java

public static boolean uploadFile(byte[] bytes, String filename, String uploadurl) {

    HttpURLConnection conn = null;
    DataOutputStream dos = null;/*w  ww .java 2s .c o m*/
    // DataInputStream inStream = null;

    String lineEnd = "\r\n";
    String twoHyphens = "--";
    String boundary = "*****";

    int bytesRead, bytesAvailable, bufferSize;
    byte[] buffer;
    int maxBufferSize = 64 * 1024; // old value 1024*1024
    ByteArrayInputStream byteArrayInputStream = null;
    boolean isSuccess = true;
    try {
        // ------------------ CLIENT REQUEST

        byteArrayInputStream = new ByteArrayInputStream(bytes);

        // open a URL connection to the Servlet
        URL url = new URL(uploadurl);
        // Open a HTTP connection to the URL
        conn = (HttpURLConnection) url.openConnection();
        // Allow Inputs
        conn.setDoInput(true);
        // Allow Outputs
        conn.setDoOutput(true);
        // Don't use a cached copy.
        conn.setUseCaches(false);
        // set timeout
        conn.setConnectTimeout(60000);
        conn.setReadTimeout(60000);
        // Use a post method.
        conn.setRequestMethod("POST");
        conn.setRequestProperty("Connection", "Keep-Alive");
        conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);

        dos = new DataOutputStream(conn.getOutputStream());
        dos.writeBytes(twoHyphens + boundary + lineEnd);
        dos.writeBytes("Content-Disposition: form-data; name=\"uploadedfile\";filename=\"" + filename + "\""
                + lineEnd);
        dos.writeBytes(lineEnd);

        // create a buffer of maximum size
        bytesAvailable = byteArrayInputStream.available();
        bufferSize = Math.min(bytesAvailable, maxBufferSize);
        buffer = new byte[bufferSize];

        // read file and write it into form...
        bytesRead = byteArrayInputStream.read(buffer, 0, bufferSize);
        while (bytesRead > 0) {
            dos.write(buffer, 0, bufferSize);
            bytesAvailable = byteArrayInputStream.available();
            bufferSize = Math.min(bytesAvailable, maxBufferSize);
            bytesRead = byteArrayInputStream.read(buffer, 0, bufferSize);
        }

        // send multipart form data necesssary after file data...
        dos.writeBytes(lineEnd);
        dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);

        // close streams
        // Log.e(TAG,"UploadService Runnable:File is written");
        // fileInputStream.close();
        // dos.flush();
        // dos.close();
    } catch (Exception e) {
        // Log.e(TAG, "UploadService Runnable:Client Request error", e);
        isSuccess = false;
    } finally {
        if (dos != null) {
            try {
                dos.close();
            } catch (IOException e) {
                // Log.e(TAG, "exception" + e);

            }
        }
        if (byteArrayInputStream != null) {
            try {
                byteArrayInputStream.close();
            } catch (IOException e) {
                // Log.e(TAG, "exception" + e);

            }
        }

    }

    // ------------------ read the SERVER RESPONSE
    try {

        if (conn.getResponseCode() != 200) {
            isSuccess = false;
        }
    } catch (IOException e) {
        // Log.e(TAG, "Connection error", e);
        isSuccess = false;
    }

    return isSuccess;
}

From source file:com.qualogy.qafe.bind.core.application.io.ResourceMerger.java

@SuppressWarnings("unchecked")
public static ApplicationMapping merge(Class mergeableClassName, List<ApplicationMapping> concreteMappings,
        List<FileLocation> fileLocations, String appName, String root, boolean autoScanRoot,
        boolean recursiveScan, boolean validating) {

    logger.log(Level.FINE, "Start merging application mappings for application [{0}]", appName);

    ApplicationMapping applicationMapping = null;

    //boolean to see whether a concrete and/or location is/are set
    boolean noMappings = ((concreteMappings == null || concreteMappings.isEmpty())
            && (fileLocations == null || fileLocations.isEmpty()));

    ByteArrayInputStream in = null;
    try {//www.j a va2s .co m

        if (concreteMappings != null) {
            for (ApplicationMapping mapping : concreteMappings) {
                if (applicationMapping != null)
                    throw new LoadFailedException(appName,
                            "loading two application-mappings through application-context without resource is not yet supported");
                if ((fileLocations == null || fileLocations.isEmpty())) {
                    applicationMapping = mapping;
                } else {
                    ByteArrayOutputStream out = null;
                    try {
                        out = new ByteArrayOutputStream();
                        new Writer().write(mapping, out, false);
                        byte[] bytes = out.toByteArray();
                        in = new ByteArrayInputStream(bytes);
                    } finally {
                        if (out != null)
                            try {
                                out.close();
                            } catch (IOException e) {
                                logger.log(Level.SEVERE,
                                        "Error occured while closing outputstream for application: " + appName,
                                        e);
                            }
                    }
                }
            }
        }

        if (noMappings || fileLocations != null) {
            List<URI> filePaths = new ArrayList<URI>();
            if (noMappings && autoScanRoot) {
                logger.warning("No application-mapping found for context, using root [" + root
                        + "] to scan for application-mapping (since auto-scan-root is set to true)");
                filePaths.add(new FileLocation(root, "").toURI());
            } else if (noMappings && !autoScanRoot) {
                throw new LoadFailedException(appName,
                        "No application-mapping found and auto-scan is false (default), cannot startup without application-mapping");
            } else if (fileLocations != null) {
                for (FileLocation location : fileLocations) {
                    location.setRoot(root);
                    URI path = location.toURI();
                    if (path == null)
                        throw new BindException(
                                "No file found at mapping file location [" + location.toString() + "]");
                    filePaths.add(path);
                }
            }

            logger.info("Start reading application mappings for application [" + appName + "] from ["
                    + filePaths + "]");

            try {
                applicationMapping = (ApplicationMapping) new Reader(ApplicationMapping.class).read(in,
                        filePaths, root, recursiveScan);
            } catch (RuntimeException e) {
                String message = e != null ? e.getMessage() : null;
                throw new LoadFailedException(appName, message, e);
            }

            logger.info("Finished reading application mappings for application [" + appName + "]");
        }
    } finally {
        try {
            if (in != null)
                in.close();
        } catch (IOException e) {
            logger.log(Level.SEVERE, "Error occured while closing inputstream", e);
        }
    }

    return applicationMapping;
}

From source file:com.knowgate.dfs.FileSystem.java

/**
 * Read a serializable object from a text file
 * @param sFilePath Full file path. For example "file:///tmp/myfile.bin" or "ftp://localhost:21/tmp/myfile.bin"
 * @throws MalformedURLException if sFilePath does not begin with file://or ftp://
 * @throws ClassNotFoundException//from  w  w  w . jav a  2s  . com
 * @throws FileNotFoundException
 * @throws IOException
 * @since 4.0
 */

public Object readfileobj(String sFilePath)
        throws MalformedURLException, FileNotFoundException, IOException, FTPException, ClassNotFoundException {
    Object oRetVal;
    ObjectInputStream oObjStrm;

    String sLower = sFilePath.toLowerCase();

    if (sLower.startsWith("file://")) {
        sFilePath = sFilePath.substring(7);

        FileInputStream oInStrm = new FileInputStream(sFilePath);
        oObjStrm = new ObjectInputStream(oInStrm);
        oRetVal = oObjStrm.readObject();
        oObjStrm.close();
        oInStrm.close();
    } else if (sLower.startsWith("ftp://")) {
        byte[] aFileBytes = readfilebin(sFilePath);
        ByteArrayInputStream oBteStrm = new ByteArrayInputStream(aFileBytes);
        oObjStrm = new ObjectInputStream(oBteStrm);
        oRetVal = oObjStrm.readObject();
        oObjStrm.close();
        oBteStrm.close();
    } else {
        throw new MalformedURLException(
                "FileSystem.readfileobj(" + sFilePath + ") File protocol must begin with file:// or ftp://");
    }
    return oRetVal;
}