Example usage for java.io IOException getClass

List of usage examples for java.io IOException getClass

Introduction

In this page you can find the example usage for java.io IOException getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:org.fcrepo.utilities.install.FedoraHome.java

private void configureAkubra() throws InstallationFailedException {
    if (usingAkubra()) {
        // Rewrite server/config/akubra-llstore.xml replacing the
        // /tmp/[object|datastream]Store constructor-arg values
        // with $FEDORA_HOME/data/[object|datastream]Store
        BufferedReader reader = null;
        PrintWriter writer = null;
        try {/*from  w  ww .j  ava  2s  .c o  m*/
            File file = new File(_installDir, "server/config/spring/akubra-llstore.xml");
            reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));

            File dataDir = new File(_installDir, "data");
            String oPath = dataDir.getPath() + File.separator + "objectStore";
            String dPath = dataDir.getPath() + File.separator + "datastreamStore";
            StringBuilder xml = new StringBuilder();

            String line = reader.readLine();
            while (line != null) {
                if (line.indexOf("/tmp/objectStore") != -1) {
                    line = "    <constructor-arg value=\"" + oPath + "\"/>";
                } else if (line.indexOf("/tmp/datastreamStore") != -1) {
                    line = "    <constructor-arg value=\"" + dPath + "\"/>";
                }
                xml.append(line + "\n");
                line = reader.readLine();
            }
            reader.close();

            writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
            writer.print(xml.toString());
            writer.close();
        } catch (IOException e) {
            IOUtils.closeQuietly(reader);
            IOUtils.closeQuietly(writer);
            throw new InstallationFailedException(e.getClass().getName() + ":" + e.getMessage());
        }
    } else {
        // remove the stub akubra configuration
        File file = new File(_installDir, "server/config/spring/akubra-llstore.xml");
        file.delete();
        if (file.exists()) {
            throw new InstallationFailedException("Could not remove a conflicting config: akubra-llstore.xml");
        }
    }
}

From source file:com.aol.advertising.qiao.injector.file.AbstractFileTailer.java

protected RandomAccessFile getChecksumAndResetPositionKey(RandomAccessFile raf)
        throws QiaoOperationException, InterruptedException {
    while (running) {
        try {// w w w .  j  a  va2 s  .c o m
            long crc = checksum(raf);
            _position.setKey(crc); // set checksum as the key

            logger.info(">> New file's checksum=" + crc);

            return raf;
        } catch (IOException e) {
            logger.error(e.getClass().getName() + ": " + e.getMessage());
            throw new QiaoOperationException("Unable to get checksum", e);
        } catch (InsufficientFileLengthException e) {
            // not enough data

            if (this.newFileDetected.compareAndSet(true, false)) {
                logger.info("=> switch to process the new file");
                IOUtils.closeQuietly(raf);

                raf = openFile(tailedFile);
                notifyListenerOnOpen(tailedFile.getAbsolutePath()); // let listeners know
                continue;
            }
            /*
            // in case someone deletes the file
            long len = tailedFile.length();
            if (len > checksumByteLength)
            {
            logger.warn("Discrepancy between current file descriptor and current file => close and re-open");
            IOUtils.closeQuietly(raf);
                    
            raf = openFile(tailedFile);
            notifyListenerOnOpen(tailedFile.getAbsolutePath()); // let listeners know
            continue;
            }*/
        }

        CommonUtils.sleepQuietly(fileCheckDelayMillis);
    }

    return raf;
}

From source file:me.schiz.jmeter.protocol.imap.sampler.IMAPSampler.java

private SampleResult sampleNoop(SampleResult sr) {
    SocketClient soclient = SessionStorage.getInstance().getClient(getSOClient());
    IMAPClient client = null;/*from  w ww.  j  a  v a2  s. c o m*/
    if (soclient instanceof IMAPClient)
        client = (IMAPClient) soclient;

    boolean success = false;
    String request = "NOOP\n";
    request += "Client : " + getClient() + "\n";
    sr.setRequestHeaders(request);
    if (client == null) {
        clientNotFound(sr);
        return sr;
    } else {
        synchronized (client) {
            sr.sampleStart();
            try {
                success = client.noop();
                if (getCheckSuccessful()) {
                    sr.setSuccessful(success);
                    if (success)
                        sr.setResponseCodeOK();
                    else
                        sr.setResponseCode(RC_ERROR);
                } else {
                    sr.setSuccessful(true);
                    sr.setResponseCodeOK();
                }
                sr.setResponseData(client.getReplyString().getBytes());
            } catch (IOException e) {
                sr.setSuccessful(false);
                sr.setResponseData(e.toString().getBytes());
                sr.setResponseCode(e.getClass().getName());
                log.error("client `" + getClient() + "` io exception", e);
                removeClient();
            }
            sr.sampleEnd();
        }
    }
    return sr;
}

From source file:me.schiz.jmeter.protocol.imap.sampler.IMAPSampler.java

private SampleResult sampleLogin(SampleResult sr) {
    SocketClient soclient = SessionStorage.getInstance().getClient(getSOClient());
    IMAPClient client = null;/*w w  w .j av a2  s.co  m*/
    if (soclient instanceof IMAPClient)
        client = (IMAPClient) soclient;

    boolean success = false;
    String request = "LOGIN\n";
    request += "Client : " + getClient() + "\n";
    request += "Client Name : " + getClientName() + "\n";
    sr.setRequestHeaders(request);
    if (client == null) {
        clientNotFound(sr);
        return sr;
    } else {
        synchronized (client) {
            sr.sampleStart();
            try {
                success = client.login(getClientName(), getClientPassword());
                sr.setSuccessful(success);
                if (getCheckSuccessful()) {
                    sr.setSuccessful(success);
                    if (success)
                        sr.setResponseCodeOK();
                    else
                        sr.setResponseCode(RC_ERROR);
                } else
                    sr.setResponseCodeOK();
                sr.setResponseData(client.getReplyString().getBytes());
            } catch (IOException e) {
                sr.setSuccessful(false);
                sr.setResponseData(e.toString().getBytes());
                sr.setResponseCode(e.getClass().getName());
                log.error("client `" + getClient() + "` ", e);
                removeClient();
            }
            sr.sampleEnd();
        }
    }
    return sr;
}

From source file:me.schiz.jmeter.protocol.imap.sampler.IMAPSampler.java

private SampleResult sampleLogout(SampleResult sr) {
    SocketClient soclient = SessionStorage.getInstance().getClient(getSOClient());
    IMAPClient client = null;//from   ww  w . j  a v  a 2  s . co m
    if (soclient instanceof IMAPClient)
        client = (IMAPClient) soclient;

    boolean success = false;
    String request = "LOGOUT\n";
    request += "Client : " + getClient() + "\n";
    request += "Client Name : " + getClientName() + "\n";
    sr.setRequestHeaders(request);
    if (client == null) {
        clientNotFound(sr);
        return sr;
    } else {
        synchronized (client) {
            sr.sampleStart();
            try {
                success = client.logout();
                sr.setSuccessful(success);
                if (getCheckSuccessful()) {
                    sr.setSuccessful(success);
                    if (success)
                        sr.setResponseCodeOK();
                    else
                        sr.setResponseCode(RC_ERROR);
                } else
                    sr.setResponseCodeOK();
                sr.setResponseData(client.getReplyString().getBytes());
            } catch (IOException e) {
                sr.setSuccessful(false);
                sr.setResponseData(e.toString().getBytes());
                sr.setResponseCode(e.getClass().getName());
                log.error("client `" + getClient() + "` ", e);
                removeClient();
            }
            sr.sampleEnd();
        }
    }
    return sr;
}

From source file:me.schiz.jmeter.protocol.imap.sampler.IMAPSampler.java

private SampleResult sampleCapability(SampleResult sr) {
    SocketClient soclient = SessionStorage.getInstance().getClient(getSOClient());
    IMAPClient client = null;/*w w w .j a va 2s . c om*/
    if (soclient instanceof IMAPClient)
        client = (IMAPClient) soclient;

    boolean success = false;
    String request = "CAPABILITY \n";
    request += "Client : " + getClient() + "\n";
    request += "Client Name : " + getClientName() + "\n";
    sr.setRequestHeaders(request);
    if (client == null) {
        clientNotFound(sr);
        return sr;
    } else {
        synchronized (client) {
            sr.sampleStart();
            try {
                success = client.capability();
                sr.setSuccessful(success);
                if (getCheckSuccessful()) {
                    sr.setSuccessful(success);
                    if (success)
                        sr.setResponseCodeOK();
                    else
                        sr.setResponseCode(RC_ERROR);
                } else
                    sr.setResponseCodeOK();
                sr.setResponseData(client.getReplyString().getBytes());
            } catch (IOException e) {
                sr.setSuccessful(false);
                sr.setResponseData(e.toString().getBytes());
                sr.setResponseCode(e.getClass().getName());
                log.error("client `" + getClient() + "` ", e);
                removeClient();
            }
            sr.sampleEnd();
        }
    }
    return sr;
}

From source file:at.ac.uniklu.mobile.sportal.api.UnikluApiClient.java

private void init() {
    // init http client
    int timeout = 20000;
    HttpParams httpParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParams, timeout);
    HttpConnectionParams.setSoTimeout(httpParams, timeout);
    mHttpClient = new DefaultHttpClient(httpParams);
    mHttpClient.setHttpRequestRetryHandler(new HttpRequestRetryHandler() {
        @Override// w ww  . j  ava2s  .co  m
        public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
            logDebug("request retry " + executionCount + ": " + exception.getClass().getName());
            if (executionCount < 3) {
                if (exception instanceof SSLException) {
                    return true;
                }
                if (exception instanceof SocketTimeoutException) {
                    return true;
                }
                if (exception instanceof ConnectTimeoutException) {
                    return true;
                }
            }
            return false;
        }
    });

    // init gson & configure it to match server's output format
    mGson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
            .setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
            .registerTypeAdapter(Notification.Type.class, new GsonNotificationTypeDeserializer()).create();
}

From source file:net.modelbased.proasense.storage.fuseki.StorageRegistryFusekiService.java

private Properties loadServerProperties() {
    serverProperties = new Properties();
    String propFilename = "server.properties";
    InputStream inputStream = getClass().getClassLoader().getResourceAsStream(propFilename);

    try {//from   ww w  . j  av  a 2 s  .  c o  m
        if (inputStream != null) {
            serverProperties.load(inputStream);
        } else
            throw new FileNotFoundException("Property file: '" + propFilename + "' not found in classpath.");
    } catch (IOException e) {
        System.out.println(e.getClass().getName() + ": " + e.getMessage());
    }

    return serverProperties;
}

From source file:me.schiz.jmeter.protocol.imap.sampler.IMAPSampler.java

private SampleResult sampleCommand(SampleResult sr) {
    SocketClient soclient = SessionStorage.getInstance().getClient(getSOClient());
    IMAPClient client = null;//from  w  ww .  ja  va 2 s.c om
    if (soclient instanceof IMAPClient)
        client = (IMAPClient) soclient;

    boolean success = false;
    String request = "COMMAND\n";
    request += "Client : " + getClient() + "\n";
    request += "Client Name : " + getClientName() + "\n";
    request += "Command : `" + getCommand() + " " + getCommandArgs() + "`\n";
    sr.setRequestHeaders(request);
    if (client == null) {
        clientNotFound(sr);
        return sr;
    } else {
        synchronized (client) {
            sr.sampleStart();
            try {
                if (getCommandArgs().isEmpty()) {
                    success = client.doCommand(IMAPCommand.valueOf(getCommand()));
                } else {
                    success = client.doCommand(IMAPCommand.valueOf(getCommand()), getCommandArgs());
                }
                sr.setSuccessful(success);
                if (getCheckSuccessful()) {
                    sr.setSuccessful(success);
                    if (success)
                        sr.setResponseCodeOK();
                    else
                        sr.setResponseCode(RC_ERROR);
                } else
                    sr.setResponseCodeOK();
                sr.setResponseData(client.getReplyString().getBytes());
            } catch (IOException e) {
                sr.setSuccessful(false);
                sr.setResponseData(e.toString().getBytes());
                sr.setResponseCode(e.getClass().getName());
                log.error("client `" + getClient() + "` ", e);
                removeClient();
            }
            sr.sampleEnd();
        }
    }
    return sr;
}

From source file:photosharing.api.conx.CommentsDefinition.java

/**
 * creates a new comment with a given library id and document id
 * /*from   ww  w. j  a va 2 s . co m*/
 * @param bearer
 *            the accesstoken used to make the request
 * @param pid
 *            the document id
 * @param uid
 *            the library id
 * @param body
 *            the body of the comment
 * @param nonce
 *            the nonce code
 * @param response
 *            the http response that the results are sent to
 */
public void createComment(String bearer, String pid, String uid, String body, String nonce,
        HttpServletResponse response) {
    String apiUrl = getApiUrl() + "/library/" + uid + "/document/" + pid + "/feed";

    logger.info(apiUrl);

    try {
        JSONObject obj = new JSONObject(body);

        String comment = generateComment(obj.getString("comment"));

        // Generate the
        Request post = Request.Post(apiUrl);
        post.addHeader("Authorization", "Bearer " + bearer);
        post.addHeader("X-Update-Nonce", nonce);
        post.addHeader("Content-Type", "application/atom+xml");

        ByteArrayEntity entity = new ByteArrayEntity(comment.getBytes("UTF-8"));
        post.body(entity);

        Executor exec = ExecutorUtil.getExecutor();
        Response apiResponse = exec.execute(post);
        HttpResponse hr = apiResponse.returnResponse();

        /**
         * Check the status codes
         */
        int code = hr.getStatusLine().getStatusCode();

        // Process the Status Codes
        if (code == HttpStatus.SC_FORBIDDEN) {
            // Session is no longer valid or access token is expired
            response.setStatus(HttpStatus.SC_FORBIDDEN);
        } else if (code == HttpStatus.SC_UNAUTHORIZED) {
            // User is not authorized
            response.setStatus(HttpStatus.SC_UNAUTHORIZED);
        } else if (code == HttpStatus.SC_CREATED) {
            // Default to 201
            response.setStatus(HttpStatus.SC_OK);

            InputStream in = hr.getEntity().getContent();

            String jsonString = org.apache.wink.json4j.utils.XML.toJson(in);

            JSONObject base = new JSONObject(jsonString);
            JSONObject entry = base.getJSONObject("entry");
            JSONObject author = entry.getJSONObject("author");

            String name = author.getString("name");
            String userid = author.getString("userid");
            String date = entry.getString("modified");
            String content = entry.getString("content");
            String cid = entry.getString("uuid");

            // Build the JSON object
            JSONObject commentJSON = new JSONObject();
            commentJSON.put("uid", userid);
            commentJSON.put("author", name);
            commentJSON.put("date", date);
            commentJSON.put("content", content);
            commentJSON.put("cid", cid);

            // Flush the Object to the Stream with content type
            response.setHeader("Content-Type", "application/json");

            PrintWriter out = response.getWriter();
            out.write(commentJSON.toString());
            out.flush();
            out.close();

        }

    } catch (IOException e) {
        response.setHeader("X-Application-Error", e.getClass().getName());
        response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
        logger.severe("Issue with create comment " + e.toString());
    } catch (JSONException e) {
        response.setHeader("X-Application-Error ", e.getClass().getName());
        response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
        logger.severe("Issue with create comment " + e.toString());
        e.printStackTrace();
    } catch (SAXException e) {
        response.setHeader("X-Application-Error", e.getClass().getName());
        response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
        logger.severe("Issue with create comment " + e.toString());
    }
}