Example usage for java.io FileNotFoundException getLocalizedMessage

List of usage examples for java.io FileNotFoundException getLocalizedMessage

Introduction

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

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:org.pentaho.di.trans.step.filestream.FileStream.java

public boolean init(StepMetaInterface stepMetaInterface, StepDataInterface stepDataInterface) {
    super.init(stepMetaInterface, stepDataInterface);

    Preconditions.checkNotNull(stepMetaInterface);
    fileStreamMeta = (FileStreamMeta) stepMetaInterface;

    String sourceFile = getFilePath(fileStreamMeta.getSourcePath());

    RowMeta rowMeta = new RowMeta();
    rowMeta.addValueMeta(new ValueMetaString("line"));

    window = new FixedTimeStreamWindow<>(subtransExecutor, rowMeta, getDuration(), getBatchSize());

    try {/*from w  ww.  j a v  a  2 s.  com*/
        source = new TailFileStreamSource(sourceFile, this);
    } catch (FileNotFoundException e) {
        logError(e.getLocalizedMessage(), e);
        return false;
    }
    return true;
}

From source file:org.runbuddy.tomahawk.dialogs.RemovePluginConfigDialog.java

@Override
protected void onPositiveAction() {
    File destDir = new File(mScriptResolver.getScriptAccount().getPath().replaceFirst("file:", ""));
    try {//ww w.j ava 2  s  .co  m
        VariousUtils.deleteRecursive(destDir);
        mScriptResolver.getScriptAccount().unregisterAllPlugins();
    } catch (FileNotFoundException e) {
        Log.d(TAG, "onPositiveAction: " + e.getClass() + ": " + e.getLocalizedMessage());
    }
    PipeLine.get().removeResolver(mScriptResolver);
    dismiss();
}

From source file:org.tomahawk.tomahawk_android.dialogs.RemovePluginConfigDialog.java

@Override
protected void onPositiveAction() {
    File destDir = new File(mScriptResolver.getScriptAccount().getPath().replaceFirst("file:", ""));
    try {/*from  w  ww  . j  a va2  s .c  om*/
        VariousUtils.deleteRecursive(destDir);
        mScriptResolver.getScriptAccount().unregisterAllPlugins();
    } catch (FileNotFoundException e) {
        Log.d(TAG, "onPositiveAction: " + e.getClass() + ": " + e.getLocalizedMessage());
    }
    dismiss();
}

From source file:org.wso2.carbon.attachment.mgt.core.dao.impl.jdbc.dao.AttachmentMgtDAOFactoryImpl.java

@Override
public AttachmentDAO addAttachment(Attachment attachment) throws AttachmentMgtException {
    //Following AttachmentDAO object creation is just to check it's functionality
    String name = "JDBC Sample Name";
    String owner = "JDBC Sample Author";
    String contentType = "JDBC Sample Content Type";
    int instanceID = 789;
    InputStream stream = null;//from  w  w  w . j av a 2 s. co m
    try {
        stream = new FileInputStream(new File("/home/denis/Desktop/note.txt"));
    } catch (FileNotFoundException e) {
        log.error(e.getLocalizedMessage(), e);
    }

    String insertAttachment = "INSERT INTO ATTACHMENT (NAME, CREATED_BY, "
            + "CONTENT_TYPE, INSTANCE_ID, URL, CONTENT" + ") VALUES (?,?,?,?,?,?)";

    try {
        log.warn("Having connection at Class level is wrong here.");
        statement = connection.prepareStatement(insertAttachment);

        statement.setString(1, name);
        statement.setString(2, owner);
        statement.setString(3, contentType);
        //statement.setInt(4, attachment.getInstanceId().intValue());
        statement.setInt(4, instanceID);
        statement.setString(5, URLGeneratorUtil.generateURL());
        log.warn("URL generation part should be properly implemented.");

        statement.setBlob(6, stream);
        log.warn("Please check this cast can be avoid with good design patterns.");

        statement.executeUpdate();
    } catch (SQLException e) {
        log.error(e.getMessage(), e);
    }

    return null;
}

From source file:com.networkmanagerapp.SettingBackgroundUploader.java

/**
 * Performs the file upload in the background
 * @throws FileNotFoundException, IOException, both caught internally. 
 * @param arg0 The intent to run in the background.
 *///from   w  w w .ja v  a  2s .c  o m
@Override
protected void onHandleIntent(Intent arg0) {
    configFilePath = arg0.getStringExtra("CONFIG_FILE_PATH");
    key = arg0.getStringExtra("KEY");
    value = arg0.getStringExtra("VALUE");
    mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    showNotification();
    try {
        fos = NetworkManagerMainActivity.getInstance().openFileOutput(this.configFilePath,
                Context.MODE_PRIVATE);
        String nameLine = "Name" + " = " + "\"" + this.key + "\"\n";
        String valueLine = "Value" + " = " + "\"" + this.value + "\"";
        fos.write(nameLine.getBytes());
        fos.write(valueLine.getBytes());
        fos.close();

        String password = PreferenceManager.getDefaultSharedPreferences(this).getString("password_preference",
                "");
        File f = new File(NetworkManagerMainActivity.getInstance().getFilesDir() + "/" + this.configFilePath);
        HttpHost targetHost = new HttpHost(
                PreferenceManager.getDefaultSharedPreferences(this).getString("ip_preference", "192.168.1.1"),
                1080, "http");
        DefaultHttpClient client = new DefaultHttpClient();
        client.getCredentialsProvider().setCredentials(
                new AuthScope(targetHost.getHostName(), targetHost.getPort()),
                new UsernamePasswordCredentials("root", password));
        HttpPost httpPost = new HttpPost("http://"
                + PreferenceManager.getDefaultSharedPreferences(NetworkManagerMainActivity.getInstance())
                        .getString("ip_preference", "192.168.1.1")
                + ":1080/cgi-bin/upload.php");
        MultipartEntity entity = new MultipartEntity();
        entity.addPart("file", new FileBody(f));
        httpPost.setEntity(entity);
        HttpResponse response = client.execute(httpPost);
        Log.d("upload", response.getStatusLine().toString());
    } catch (FileNotFoundException e) {
        Log.e("NETWORK_MANAGER_XU_FNFE", e.getLocalizedMessage());
    } catch (IOException e) {
        Log.e("NETWORK_MANAGER_XU_IOE", e.getLocalizedMessage());
    } finally {
        mNM.cancel(R.string.upload_service_started);
        stopSelf();
    }
}

From source file:com.googlecode.jgenhtml.JGenXmlTest.java

private Document getXmlPage(final String relativePathToFile) {
    Document result = null;/*w w w  .j a  v  a  2 s  . c om*/
    File page = getReportFile(relativePathToFile);
    if (page.exists()) {
        try {
            result = JGenHtmlUtils.loadXmlDoc(new FileInputStream(page));
        } catch (FileNotFoundException ex) {
            fail("Could not parse " + page.getAbsolutePath() + " " + ex.getLocalizedMessage());
        }
    } else {
        fail("Could not find " + page.getAbsolutePath());
    }
    return result;
}

From source file:org.runbuddy.tomahawk.dialogs.InstallPluginConfigDialog.java

@Override
protected void onPositiveAction() {
    new Thread(new Runnable() {
        @Override// w  ww  . j av a2 s . co m
        public void run() {
            String destDirPath = TomahawkApp.getContext().getFilesDir().getAbsolutePath() + File.separator
                    + "manualresolvers" + File.separator + ".temp";
            File destDir = new File(destDirPath);
            try {
                VariousUtils.deleteRecursive(destDir);
            } catch (FileNotFoundException e) {
                Log.d(TAG, "onPositiveAction: " + e.getClass() + ": " + e.getLocalizedMessage());
            }
            try {
                if (UnzipUtils.unzip(mPathToAxe, destDirPath)) {
                    File metadataFile = new File(
                            destDirPath + File.separator + "content" + File.separator + "metadata.json");
                    String metadataString = FileUtils.readFileToString(metadataFile, Charsets.UTF_8);
                    ScriptResolverMetaData metaData = GsonHelper.get().fromJson(metadataString,
                            ScriptResolverMetaData.class);
                    final File renamedFile = new File(destDir.getParent() + File.separator + metaData.pluginName
                            + "_" + System.currentTimeMillis());
                    boolean success = destDir.renameTo(renamedFile);
                    if (!success) {
                        Log.e(TAG, "onPositiveAction - Wasn't able to rename directory: "
                                + renamedFile.getAbsolutePath());
                    }
                    new Handler(Looper.getMainLooper()).post(new Runnable() {
                        @Override
                        public void run() {
                            PipeLine.get().addScriptAccount(new ScriptAccount(renamedFile.getPath(), true));
                        }
                    });
                }
            } catch (IOException e) {
                Log.e(TAG, "onPositiveAction: " + e.getClass() + ": " + e.getLocalizedMessage());
            }
        }
    }).start();
    dismiss();
}

From source file:org.tomahawk.tomahawk_android.dialogs.InstallPluginConfigDialog.java

@Override
protected void onPositiveAction() {
    new Thread(new Runnable() {
        @Override//from w w w .ja v  a 2  s .c om
        public void run() {
            String destDirPath = TomahawkApp.getContext().getFilesDir().getAbsolutePath() + File.separator
                    + "manualresolvers" + File.separator + ".temp";
            File destDir = new File(destDirPath);
            try {
                VariousUtils.deleteRecursive(destDir);
            } catch (FileNotFoundException e) {
                Log.d(TAG, "onPositiveAction: " + e.getClass() + ": " + e.getLocalizedMessage());
            }
            try {
                if (UnzipUtility.unzip(mPathToAxe, destDirPath)) {
                    File metadataFile = new File(
                            destDirPath + File.separator + "content" + File.separator + "metadata.json");
                    String metadataString = FileUtils.readFileToString(metadataFile, Charsets.UTF_8);
                    ScriptResolverMetaData metaData = GsonHelper.get().fromJson(metadataString,
                            ScriptResolverMetaData.class);
                    final File renamedFile = new File(destDir.getParent() + File.separator + metaData.pluginName
                            + "_" + System.currentTimeMillis());
                    destDir.renameTo(renamedFile);
                    new Handler(Looper.getMainLooper()).post(new Runnable() {
                        @Override
                        public void run() {
                            PipeLine.get().addScriptAccount(new ScriptAccount(renamedFile.getPath(), true));
                        }
                    });
                }
            } catch (IOException e) {
                Log.e(TAG, "onPositiveAction: " + e.getClass() + ": " + e.getLocalizedMessage());
            }
        }
    }).start();
    dismiss();
}

From source file:org.uguess.android.sysinfo.NetStateManager.java

private static void parseRawData(final ArrayList<ConnectionItem> items, Activity ac,
        HashMap<String, IpInfo> queryCache, String proto, String source, boolean ignoreState) {
    BufferedReader reader = null;
    try {//  w  w  w.j av  a2 s .  c  o  m
        reader = new BufferedReader(new InputStreamReader(new FileInputStream(source)), 4096);

        boolean first = true;
        int localOffset = -1, remOffset = -1, stateOffset = -1, stateEndOffset = -1;
        String line;

        final boolean showRemoteName = Util.getBooleanOption(ac, PSTORE_NETMANAGER, PREF_KEY_SHOW_REMOTE_NAME);
        String remoteIp;
        int portIdx;
        IpInfo remoteInfo;

        while ((line = reader.readLine()) != null) {
            if (first) {
                localOffset = line.indexOf("local_address"); //$NON-NLS-1$
                remOffset = line.indexOf("rem_address"); //$NON-NLS-1$
                if (remOffset == -1) {
                    remOffset = line.indexOf("remote_address"); //$NON-NLS-1$
                }
                stateOffset = line.indexOf("st", remOffset); //$NON-NLS-1$
                stateEndOffset = line.indexOf(' ', stateOffset);

                if (localOffset == -1 || remOffset == -1 || stateOffset == -1 || stateEndOffset == -1) {
                    Log.e(NetStateManager.class.getName(), "Unexpected " //$NON-NLS-1$
                            + proto + " header format: " //$NON-NLS-1$
                            + line);

                    break;
                }

                first = false;
            } else {
                ConnectionItem ci = new ConnectionItem();

                ci.proto = proto;

                ci.local = parseRawIP(line.substring(localOffset, remOffset).trim());

                ci.remote = parseRawIP(line.substring(remOffset, stateOffset).trim());

                if (showRemoteName) {
                    remoteIp = getValidIP(ci.remote);

                    if (remoteIp != null) {
                        remoteInfo = queryCache.get(remoteIp);

                        if (remoteInfo != null && !TextUtils.isEmpty(remoteInfo.host)) {
                            portIdx = ci.remote.lastIndexOf(':');

                            if (portIdx != -1) {
                                ci.remoteName = remoteInfo.host + ci.remote.substring(portIdx);
                            } else {
                                ci.remoteName = remoteInfo.host;
                            }
                        }
                    }
                }

                if (!ignoreState) {
                    int st = Integer.parseInt(line.substring(stateOffset, stateEndOffset).trim(), 16);

                    ci.state = "Unknown"; //$NON-NLS-1$

                    if (st > 0 && st <= SOCKET_STATES.length) {
                        ci.state = SOCKET_STATES[st - 1];
                    }
                }

                items.add(ci);
            }
        }
    } catch (FileNotFoundException fe) {
        Log.d(NetStateManager.class.getName(), "File not found: " + fe.getLocalizedMessage()); //$NON-NLS-1$
    } catch (Exception e) {
        Log.e(NetStateManager.class.getName(), e.getLocalizedMessage(), e);
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (IOException e) {
                Log.e(NetStateManager.class.getName(), e.getLocalizedMessage(), e);
            }
        }
    }
}

From source file:com.amazonaws.mturk.cmd.UpdateQualificationType.java

public void updateQualificationType(String qualTypeId, String statusString, String questionFile,
        String answerFile, String propertiesFile) throws Exception {
    String test = null;//from  w ww.  j a v  a2 s  .c o m
    String answerKey = null;
    Properties props = new Properties();
    QualificationTypeStatus status = null;

    try {
        if (questionFile != null) {
            test = new FileUtil(questionFile).getString();
        }
        if (answerFile != null) {
            answerKey = new FileUtil(answerFile).getString();
        }
    } catch (FileNotFoundException e) {
        log.error("Couldn't find one of the specified files: " + e.getLocalizedMessage(), e);
    } catch (IOException e) {
        log.error("Error reading one of the specified files: " + e.getLocalizedMessage(), e);
    }

    try {
        if (propertiesFile != null) {
            props = super.loadProperties(propertiesFile);
        }
    } catch (Exception e) {
        log.error("Failed to load properties file: " + e.getLocalizedMessage(), e);
    }

    try {
        if (statusString != null) {
            status = WsdlEnumUtil.fromStringIgnoreCase(QualificationTypeStatus.class, statusString);
        } else if (props.getProperty("status") != null) {
            status = WsdlEnumUtil.fromStringIgnoreCase(QualificationTypeStatus.class,
                    props.getProperty("status"));
        }
    } catch (IllegalArgumentException iae) {
        throw new IllegalArgumentException("Invalid status [" + statusString + "]. It should be "
                + WsdlEnumUtil.getValuesPossibilityDescription(QualificationTypeStatus.class) + ".");
    }

    Long duration = null;
    if (props.getProperty("testdurationinseconds") != null) {
        duration = Long.valueOf(props.getProperty("testdurationinseconds"));
    }
    Long retryDelay = null;
    if (props.getProperty("retrydelayinseconds") != null) {
        retryDelay = Long.valueOf(props.getProperty("retrydelayinseconds"));
    }
    Boolean autoGrant = null;
    if (props.getProperty("autogranted") != null) {
        autoGrant = Boolean.valueOf(props.getProperty("autogranted"));
    }
    Integer autoValue = null;
    if (props.getProperty("autograntedvalue") != null) {
        autoValue = Integer.valueOf(props.getProperty("autograntedvalue"));
    }

    // merge Velocity templates if any
    test = getMergedTemplate(questionFile);
    answerKey = getMergedTemplate(answerFile);

    QualificationType qt = service.updateQualificationType(qualTypeId, props.getProperty("description"), status,
            test, answerKey, duration, retryDelay, autoGrant, autoValue);
    log.info("Updated qualification type: " + qt.getQualificationTypeId());
}