Example usage for java.io FileNotFoundException toString

List of usage examples for java.io FileNotFoundException toString

Introduction

In this page you can find the example usage for java.io FileNotFoundException toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:test.TestInputFiles.java

public String[] InternalFilesForIssMgrRprts(String folderToReadResponse) {
    loggerObj.log(Level.INFO, "Inside InternalFilesForIssMgrRprts method");
    Integer index = 52;//from   w w  w .  j a v a  2 s  .  c  o  m
    BufferedReader fileReader = null;
    String fileToParse = folderToReadResponse + "/JSONResponse_";
    loggerObj.log(Level.INFO, "Going to read internally files(" + fileToParse + 1 + ".json to " + fileToParse
            + index + ".json" + ") from folder " + folderToReadResponse + "");
    String fileToParseNew = fileToParse + 1 + ".json";
    try {
        String line = "";
        //Read the file line by line
        int i = 1;
        while (i <= index) {
            String output = "";
            fileToParseNew = fileToParse + i + ".json";
            try {
                fileReader = new BufferedReader(new FileReader(fileToParseNew));
            } catch (FileNotFoundException ex) {
                loggerObj.log(Level.INFO, "Error in reading MEMDM server files from internal file"
                        + fileToParseNew + "Exception is: " + ex.toString());
            }
            while ((line = fileReader.readLine()) != null) {
                output += line;
            }
            JSONParser parser = new JSONParser();
            try {
                parser.parse(output);
            } catch (ParseException ex) {
                loggerObj.log(Level.INFO,
                        "Error in parsing MEMDM server files from internal file" + fileToParseNew);
            }
            i++;
        }
    } catch (IOException ex) {
        loggerObj.log(Level.INFO, "Error in reading MEMDM server files from internal files" + fileToParseNew);
        return null;
    } finally {
        try {
            fileReader.close();
        } catch (IOException ex) {
            loggerObj.log(Level.INFO,
                    "Error in closing the fileReader while closing the file" + fileToParseNew);
        }
    }
    return new String[] { fileToParse, index.toString() };
}

From source file:org.lockss.config.BaseConfigFile.java

/**
 * Reload the contents if changed.//from  w  w  w  . j a  va 2 s .c o  m
 */
protected void reload() throws IOException {
    m_lastAttempt = TimeBase.nowMs();
    try {
        InputStream in = openInputStream();
        if (in != null) {
            try {
                setConfigFrom(in);
            } finally {
                IOUtil.safeClose(in);
            }
        }
    } catch (FileNotFoundException ex) {
        log.debug2("File not found: " + m_fileUrl);
        m_IOException = ex;
        m_loadError = ex.toString();
        throw ex;
    } catch (IOException ex) {
        log.warning("Exception loading " + m_fileUrl + ": " + ex);
        m_IOException = ex;
        if (m_loadError == null || !StringUtil.equalStrings(ex.getMessage(), m_loadError)) {
            // Some subs set m_loadError to exception message.  Don't overwrite
            // those with message that includes java exception class
            m_loadError = ex.toString();
        }
        throw ex;
    }
}

From source file:nu.nethome.home.items.web.GraphServlet.java

/**
* This is the main enterence point of the class. This is called when a http request is
* routed to this servlet./*from  w w w  . ja v a2  s  .  c om*/
*/
public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    ServletOutputStream p = res.getOutputStream();
    Date startTime = null;
    Date stopTime = null;

    // Analyse arguments
    String fileName = req.getParameter("file");
    if (fileName != null)
        fileName = getFullFileName(fromURL(fileName));
    String startTimeString = req.getParameter("start");
    String stopTimeString = req.getParameter("stop");
    try {
        if (startTimeString != null) {
            startTime = m_Format.parse(startTimeString);
        }
        if (stopTimeString != null) {
            stopTime = m_Format.parse(stopTimeString);
        }
    } catch (ParseException e1) {
        e1.printStackTrace();
    }
    String look = req.getParameter("look");
    if (look == null)
        look = "";

    TimeSeries timeSeries = new TimeSeries("Data", Minute.class);

    // Calculate time window
    Calendar cal = Calendar.getInstance();
    Date currentTime = cal.getTime();
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    Date startOfDay = cal.getTime();
    cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
    Date startOfWeek = cal.getTime();
    cal.set(Calendar.DAY_OF_MONTH, 1);
    Date startOfMonth = cal.getTime();
    cal.set(Calendar.MONTH, Calendar.JANUARY);
    Date startOfYear = cal.getTime();

    // if (startTime == null) startTime = startOfWeek;
    if (stopTime == null)
        stopTime = currentTime;
    if (startTime == null)
        startTime = new Date(stopTime.getTime() - 1000L * 60L * 60L * 24L * 2L);

    try {
        // Open the data file
        File logFile = new File(fileName);
        Scanner fileScanner = new Scanner(logFile);
        Long startTimeMs = startTime.getTime();
        Long month = 1000L * 60L * 60L * 24L * 30L;
        boolean doOptimize = true;
        boolean justOptimized = false;
        try {
            while (fileScanner.hasNext()) {
                try {
                    // Get next log entry
                    String line = fileScanner.nextLine();
                    if (line.length() > 21) {
                        // Adapt the time format
                        String minuteTime = line.substring(0, 16).replace('.', '-');
                        // Parse the time stamp
                        Minute min = Minute.parseMinute(minuteTime);

                        // Ok, this is an ugly optimization. If the current time position in the file
                        // is more than a month (30 days) ahead of the start of the time window, we
                        // quick read two weeks worth of data, assuming that there is 4 samples per hour.
                        // This may lead to scanning past start of window if there are holes in the data
                        // series.
                        if (doOptimize && ((startTimeMs - min.getFirstMillisecond()) > month)) {
                            for (int i = 0; (i < (24 * 4 * 14)) && fileScanner.hasNext(); i++) {
                                fileScanner.nextLine();
                            }
                            justOptimized = true;
                            continue;
                        }
                        // Detect if we have scanned past the window start position just after an optimization scan.
                        // If this is the case it may be because of the optimization. In that case we have to switch 
                        // optimization off and start over.
                        if ((min.getFirstMillisecond() > startTimeMs) && doOptimize && justOptimized) {
                            logFile = new File(fileName);
                            fileScanner = new Scanner(logFile);
                            doOptimize = false;
                            continue;
                        }
                        justOptimized = false;
                        // Check if value is within time window
                        if ((min.getFirstMillisecond() > startTimeMs)
                                && (min.getFirstMillisecond() < stopTime.getTime())) {
                            // Parse the value
                            double value = Double.parseDouble((line.substring(20)).replace(',', '.'));
                            // Add the entry
                            timeSeries.add(min, value);
                            doOptimize = false;
                        }
                    }
                } catch (SeriesException se) {
                    // Bad entry, for example due to duplicates at daylight saving time switch
                } catch (NumberFormatException nfe) {
                    // Bad number format in a line, try to continue
                }
            }
        } catch (Exception e) {
            System.out.println(e.toString());
        } finally {
            fileScanner.close();
        }
    } catch (FileNotFoundException f) {
        System.out.println(f.toString());
    }

    // Create a collection for plotting
    TimeSeriesCollection data = new TimeSeriesCollection();
    data.addSeries(timeSeries);

    JFreeChart chart;

    int xSize = 750;
    int ySize = 450;
    // Customize colors and look of the Graph.
    if (look.equals("mobtemp")) {
        // Look for the mobile GUI
        chart = ChartFactory.createTimeSeriesChart(null, null, null, data, false, false, false);
        XYPlot plot = chart.getXYPlot();
        ValueAxis timeAxis = plot.getDomainAxis();
        timeAxis.setAxisLineVisible(false);
        ValueAxis valueAxis = plot.getRangeAxis(0);
        valueAxis.setAxisLineVisible(false);
        xSize = 175;
        ySize = 180;
    } else {
        // Create a Chart with time range as heading
        SimpleDateFormat localFormat = new SimpleDateFormat();
        String heading = localFormat.format(startTime) + " - " + localFormat.format(stopTime);
        chart = ChartFactory.createTimeSeriesChart(heading, null, null, data, false, false, false);

        Paint background = new Color(0x9D8140);
        chart.setBackgroundPaint(background);
        TextTitle title = chart.getTitle(); // fix title
        Font titleFont = title.getFont();
        titleFont = titleFont.deriveFont(Font.PLAIN, (float) 14.0);
        title.setFont(titleFont);
        title.setPaint(Color.darkGray);
        XYPlot plot = chart.getXYPlot();
        plot.setBackgroundPaint(background);
        plot.setDomainGridlinePaint(Color.darkGray);
        ValueAxis timeAxis = plot.getDomainAxis();
        timeAxis.setAxisLineVisible(false);
        ValueAxis valueAxis = plot.getRangeAxis(0);
        valueAxis.setAxisLineVisible(false);
        plot.setRangeGridlinePaint(Color.darkGray);
        XYItemRenderer renderer = plot.getRenderer(0);
        renderer.setSeriesPaint(0, Color.darkGray);
        xSize = 750;
        ySize = 450;
    }

    try {
        res.setContentType("image/png");
        res.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
        res.setHeader("Pragma", "no-cache");
        res.setStatus(HttpServletResponse.SC_OK);
        ChartUtilities.writeChartAsPNG(p, chart, xSize, ySize);
    } catch (IOException e) {
        System.err.println("Problem occurred creating chart.");
    }

    p.flush();
    p.close();
    return;
}

From source file:apim.restful.exportimport.APIService.java

/**
 * Store custom sequences in the archive directory
 *
 * @param sequenceConfig   Sequence configuration
 * @param sequenceName     Sequence name
 * @param direction        Direction of the sequence "in", "out" or "fault"
 * @throws APIExportException  If an error occurs while serializing XML stream or storing in
 * archive directory/*from   ww  w .  j ava2s.co  m*/
 */
private void exportSequence(OMElement sequenceConfig, String sequenceName, String direction)
        throws APIExportException {
    OutputStream outputStream = null;
    try {
        createDirectory(baseAPIArchivePath + "/Sequences/" + direction + "-sequence");
        outputStream = new FileOutputStream(
                baseAPIArchivePath + "/Sequences/" + direction + "-sequence/" + sequenceName + "" + ".xml");
        sequenceConfig.serialize(outputStream);
    } catch (FileNotFoundException e) {
        log.error("Unable to find file" + e.toString());
        throw new APIExportException("Unable to find file: " + baseAPIArchivePath + "/Sequences/" + direction
                + "-sequence/" + sequenceName + "" + ".xml", e);
    } catch (XMLStreamException e) {
        log.error("Error while processing XML stream" + e.toString());
        throw new APIExportException("Error while processing XML stream", e);
    }
}

From source file:com.radiohitwave.ftpsync.API.java

public String DownloadApplicationFile() throws IOException {
    try {//  w  w  w.j  a va2  s .c  o  m
        URL website = new URL(this.apiDomain + this.updateRemoteFile + "?" + System.nanoTime());
        ReadableByteChannel rbc = Channels.newChannel(website.openStream());
        File downloadFolder = new File(this.tempFilePath);
        downloadFolder.mkdirs();
        FileOutputStream fos = new FileOutputStream(this.tempFilePath + "/" + this.updateLocalFile);
        fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
        return this.tempFilePath;
    } catch (FileNotFoundException ex) {
        Log.error(ex.toString());
        Log.remoteError(ex);
    }
    return null;
}

From source file:at.ac.tuwien.caa.docscan.logic.DataLog.java

public void readLog(Context context) {

    try {/*from  w w  w  .  j a v a  2  s.co  m*/
        String fileName = getLogFileName(context);
        InputStream in = new FileInputStream(new File(fileName));
        mShotLogs = readJsonStream(in);

    } catch (FileNotFoundException e) {
        //            There is no log existing, create a new one:
    } catch (Exception e) {
        Log.d(getClass().getName(), e.toString());
    }

    if (mShotLogs == null)
        mShotLogs = new ArrayList();
}

From source file:org.apache.hadoop.hive.ql.exec.persistence.SortedKeyValueList.java

public V get(K key) throws HiveException {

    int compareResult;
    Object key0 = ((ArrayList<Object>) key).get(0);

    if (key0 == null) {
        return null;
    }/*from w w  w  .j  av  a  2  s.  c  o m*/

    if (lastKey != null) {
        compareResult = compareKeys(lastKey, key0);
        if (compareResult > 0) {
            reset();
        }
    }

    if (mIndex < mSize) {

        do {
            compareResult = compareKeys(mKeyList.get(mIndex), key0);
            if (compareResult == 0) {
                lastKey = key0;
                return mValueList.get(mIndex);
            } else if (compareResult > 0) {
                lastKey = key0;
                return null;
            } else {
                mIndex++;
            }
        } while (mIndex < mSize);

        if (oInput == null) {
            try {
                if (pFile == null) {
                    lastKey = key0;
                    return null;
                }

                oInput = new ObjectInputStream(new FileInputStream(pFile));
            } catch (FileNotFoundException e) {
                LOG.warn(e.toString());
                throw new HiveException(e);
            } catch (IOException e) {
                LOG.warn(e.toString());
                throw new HiveException(e);
            }
        }

        if (pIndex < pSize) {

            if (currentPersistentKey == null) {
                getNewPersistentKeyValue();
            }

            do {
                compareResult = compareKeys(currentPersistentKey, key0);

                if (compareResult == 0) {
                    lastKey = key0;
                    return currentPersistentValue;
                } else if (compareResult > 0) {
                    lastKey = key0;
                    return null;
                } else {
                    getNewPersistentKeyValue();
                }
            } while (pIndex < pSize);

            lastKey = key0;
            return null;
        } else {
            lastKey = key0;
            return null;
        }
    } else {

        if (pIndex < pSize) {

            if (currentPersistentKey == null) {
                getNewPersistentKeyValue();
            }

            do {
                compareResult = compareKeys(currentPersistentKey, key0);

                if (compareResult == 0) {
                    lastKey = key0;
                    return currentPersistentValue;
                } else if (compareResult > 0) {
                    lastKey = key0;
                    return null;
                } else {
                    getNewPersistentKeyValue();
                }

            } while (pIndex < pSize);

            lastKey = key0;
            return null;
        }
    }

    lastKey = key0;
    return null;
}

From source file:org.diyefi.openlogviewer.propertypanel.PropertiesPane.java

private void loadProperties() {
    try {//from w ww  . ja v a  2  s.com
        final Scanner scan = new Scanner(new FileReader(OLVProperties));

        while (scan.hasNext()) {
            final String[] propLine = scan.nextLine().split("=");
            final SingleProperty sp = new SingleProperty();
            final String[] prop = propLine[1].split(",");
            sp.setHeader(propLine[0]);
            sp.setColor(
                    new Color(Integer.parseInt(prop[0]), Integer.parseInt(prop[1]), Integer.parseInt(prop[2])));
            sp.setMin(Double.parseDouble(prop[3]));
            sp.setMax(Double.parseDouble(prop[4]));
            sp.setTrackIndex(Integer.parseInt(prop[5]));
            sp.setActive(Boolean.parseBoolean(prop[6]));
            addProperty(sp);
        }

        scan.close();
    } catch (FileNotFoundException fnf) {
        System.out.print(fnf.toString());
        throw new RuntimeException(fnf);
    }
}

From source file:ch.dbrgn.android.simplerepost.activities.RepostActivity.java

/**
 * Add the watermark from the specified resource file onto the
 * specified image.//from   www .  j  a va 2s.c o  m
 */
private Bitmap addWatermark(String filename, int watermarkResourceFile) {
    // Read background into drawable
    BitmapDrawable background = null;
    try {
        final InputStream is = openFileInput(filename);
        background = new BitmapDrawable(getResources(), is);
        is.close();
    } catch (FileNotFoundException e) {
        ToastHelper.showShortToast(this, "Could not find downloaded image on filesystem");
        Log.e(LOG_TAG, "IOException: " + e.toString());
        return null;
    } catch (IOException e) {
        Log.w(LOG_TAG, "Could not close InputStream");
    }

    // Read watermark into Drawable
    final InputStream is = getResources().openRawResource(watermarkResourceFile);
    final BitmapDrawable watermark = new BitmapDrawable(getResources(), is);
    try {
        is.close();
    } catch (IOException e) {
        Log.w(LOG_TAG, "Could not close InputStream");
    }

    // Get dimensions
    int w = background.getBitmap().getWidth();
    int h = background.getBitmap().getHeight();

    // Create canvas for final output
    Bitmap watermarked = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(watermarked);

    // Write background onto canvas
    background.setBounds(0, 0, w, h);
    background.draw(canvas);
    background.getBitmap().recycle();

    // Write watermark onto canvas
    watermark.setBounds(0, 0, w, h);
    watermark.draw(canvas);
    watermark.getBitmap().recycle();

    return watermarked;
}

From source file:msuresh.raftdistdb.RaftClient.java

public static void SetValue(String name, String key, String value) throws FileNotFoundException {
    if (key == null || key.isEmpty()) {
        return;/*from  w w w  .j  a  va  2s  .  c  o  m*/
    }
    File configFile = new File(Constants.STATE_LOCATION + name + ".info");
    if (!configFile.exists() || configFile.isDirectory()) {
        FileNotFoundException ex = new FileNotFoundException();
        throw ex;
    }
    try {
        System.out.println("Adding key .. hold on..");
        String content = new Scanner(configFile).useDelimiter("\\Z").next();
        JSONObject config = (JSONObject) (new JSONParser()).parse(content);
        Long numPart = (Long) config.get("countPartitions");
        Integer shardId = key.hashCode() % numPart.intValue();
        JSONArray memberJson = (JSONArray) config.get(shardId.toString());
        List<Address> members = new ArrayList<>();
        for (int i = 0; i < memberJson.size(); i++) {
            JSONObject obj = (JSONObject) memberJson.get(i);
            Long port = (Long) obj.get("port");
            String address = (String) obj.get("address");
            members.add(new Address(address, port.intValue()));
        }
        CopycatClient client = CopycatClient.builder(members).withTransport(new NettyTransport()).build();
        client.open().join();
        client.submit(new PutCommand(key, value)).get();
        client.close().join();
        while (client.isOpen()) {
            Thread.sleep(1000);
        }
        System.out.println("key " + key + " with value : " + value + " has been added to the cluster");
    } catch (Exception ex) {
        System.out.println(ex.toString());
    }
}