Example usage for java.io IOException toString

List of usage examples for java.io IOException toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:com.netflix.ice.login.saml.Saml.java

public Saml(Properties properties) throws LoginMethodException {
    super(properties);
    config = new SamlConfig(properties);
    for (String signingCert : config.trustedSigningCerts) {
        try {//from   ww  w  .  java  2s .  c om
            FileInputStream fis = new FileInputStream(new File(signingCert));
            CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
            Certificate cert = certFactory.generateCertificate(fis);
            trustedSigningCerts.add(cert);
        } catch (IOException ioe) {
            logger.error("Error reading public key " + signingCert + ":" + ioe.toString());
        } catch (Exception e) {
            logger.error("Error decoding public key " + signingCert + ":" + e.toString());
        }
    }

    try {
        DefaultBootstrap.bootstrap();
    } catch (ConfigurationException ce) {
        throw new LoginMethodException("Failure to init OpenSAML: " + ce.toString());
    }
}

From source file:aes.pica.touresbalon.tb_serviciosbolivariano.ServiciosBolivarianos.java

@Override
public boolean cancelarReserva(int ordenId) {

    String nombreArchivo = Constantes.NAME_RESERVAS + ordenId + Constantes.CSV_FILE;
    Random numaleatorio = new Random(3816L);

    try {//from w w  w .j  a  v a  2 s.co m
        File archivoConsulta = FileUtils.getFile(rutaReservas, nombreArchivo);
        String nombreArchivoNvo = archivoConsulta.getParent() + "/auxiliar"
                + String.valueOf(Math.abs(numaleatorio.nextInt())) + ".txt";
        File archivoConsultaNvo = new File(nombreArchivoNvo);

        if (archivoConsulta != null && archivoConsulta.exists()) {

            br = new BufferedReader(new FileReader(archivoConsulta));
            String linea = "";

            while ((linea = br.readLine()) != null) {

                if (linea.indexOf(ordenId + ",") != -1) {
                    System.out.println("" + linea);
                    String lineaNva = null;
                    /*for (int i = 0; i <= linea.length(); i++){
                    System.out.println("Caracter " + i + ": " + linea.charAt(i));
                    if (POSICION_CANCELAR == i) {
                        lineaNva.concat("C");   
                    } else {
                        lineaNva.concat(String.valueOf(linea.charAt(i)));
                    }                            
                    }*/

                    StringTokenizer token = new StringTokenizer(linea, ".");
                    int c = 1;
                    while (token.hasMoreTokens()) {
                        if (POSICION_CANCELAR == c) {
                            lineaNva.concat("C");
                        } else {
                            System.out.println(token.nextToken());
                            lineaNva.concat(token.nextToken());
                        }
                        c++;
                    }

                    EcribirFichero(archivoConsultaNvo, linea);
                } else {
                    EcribirFichero(archivoConsulta, linea);
                }

            }
            BorrarFichero(archivoConsulta);
            archivoConsultaNvo.renameTo(archivoConsulta);
            br.close();

        } else {

            System.out.println("No existe archivo: " + nombreArchivo + " en el directorio: " + rutaReservas);

        }

        return true;

    } catch (IOException ex) {

        System.err.println(ex.toString());

    }

    return false;

}

From source file:com.board.games.handler.jl.JLPokerLoginServiceImpl.java

@Override
public LoginResponseAction handle(LoginRequestAction req) {
    // At this point, we should get the user name and password
    // from the request and verify them, but for this example
    // we'll just assign a dynamic player ID and grant the login
    try {/*from  w  ww. j av  a2  s.  co  m*/
        Ini ini = new Ini(new File("JDBCConfig.ini"));
        String jdbcDriver = ini.get("JDBCConfig", "jdbcDriver");
        String connectionUrl = ini.get("JDBCConfig", "connectionUrl");
        String database = ini.get("JDBCConfig", "database");
        dbPrefix = ini.get("JDBCConfig", "dbPrefix");
        String user = ini.get("JDBCConfig", "user");
        String password = ini.get("JDBCConfig", "password");
        jdbcDriverClassName = ini.get("JDBCConfig", "driverClassName");
        connectionStr = "jdbc" + ":" + jdbcDriver + "://" + connectionUrl + "/" + database + "?user=" + user
                + "&password=" + password;
        log.debug("user " + user);
        log.debug("connectionStr " + connectionStr);
    } catch (IOException ioe) {
        log.error("Exception in init " + ioe.toString());
    } catch (Exception e) {
        log.error("Exception in init " + e.toString());
    }

    LoginResponseAction response = null;
    try {
        log.debug("Performing authentication on " + req.getUser());
        String userIdStr = authenticate(req.getUser(), req.getPassword());
        if (!userIdStr.equals("")) {

            response = new LoginResponseAction(Integer.parseInt(userIdStr) > 0 ? true : false,
                    (req.getUser().toUpperCase().startsWith("GUESTXDEMO") ? req.getUser() + "_" + userIdStr
                            : req.getUser()),
                    Integer.parseInt(userIdStr)); // pid.incrementAndGet()
            log.debug(Integer.parseInt(userIdStr) > 0 ? "Authentication successful" : "Authentication failed");
            return response;
        }
    } catch (SQLException sqle) {
        log.error("Error authenticate", sqle);
        response = new LoginResponseAction(false, -1);
        response.setErrorMessage(getSystemErrorMessage(sqle));
        response.setErrorCode(getSystemErrorCode(sqle));
        log.error(sqle);
    } catch (Exception e) {
        log.error("Error system", e);
    }

    response = new LoginResponseAction(false, -1);
    response.setErrorMessage(getNotFoundErrorMessage());
    response.setErrorCode(getNotFoundErrorCode());
    return response;
}

From source file:ConnectionProtccol.HttpsClient.java

/**
 *
 * @param urlParams//  ww  w .  j  ava  2  s .c  o m
 * @param postParams
 * 
 */
public boolean httpsPost(String url, MultipartEntityBuilder builder, UrlEncodedFormEntity formParams) {

    loggerObj.log(Level.INFO, "Inside httpsPost method");
    CloseableHttpClient httpclient = HttpClients.createDefault();

    try {
        //  HttpPost httppost = new HttpPost("https://reportsapi.zoho.com/api/harshavardhan.r@zohocorp.com/Test/Name_password?ZOHO_ACTION=IMPORT&ZOHO_OUTPUT_FORMAT=json&ZOHO_ERROR_FORMAT=json&authtoken=7ed717b94bc30455aad11ce5d31d34f9&ZOHO_API_VERSION=1.0");
        loggerObj.log(Level.INFO, "Going to post to the zoho reports api");

        HttpPost httppost = new HttpPost(url);

        //Need to understand the difference betwween multipartentitybuilder and urlencodedformentity//
        HttpEntity entity = null;
        if (builder != null)
            entity = builder.build();

        if (formParams != null)
            entity = formParams;

        httppost.setEntity(entity);
        loggerObj.log(Level.INFO, "executing request");
        System.out.println("executing request " + httppost.getRequestLine());
        CloseableHttpResponse response = null;
        try {
            response = httpclient.execute(httppost);
        } catch (IOException ex) {
            loggerObj.log(Level.INFO, "Cannot connect to reports.zoho.com" + ex.toString());
            return false;
        }
        try {
            loggerObj.log(Level.INFO, "----------------------------------------");
            loggerObj.log(Level.INFO, response.toString());
            response.getStatusLine();
            HttpEntity resEntity = response.getEntity();
            if (resEntity != null) {
                loggerObj.log(Level.INFO, "Response content length: " + resEntity.getContentLength());
                BufferedReader rd = null;
                try {
                    rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
                } catch (IOException ex) {
                    loggerObj.log(Level.INFO,
                            "cannot read the response 1 from reports.zoho.com" + ex.toString());
                    return false;
                } catch (UnsupportedOperationException ex) {
                    loggerObj.log(Level.INFO, "cannot read the response 2" + ex.toString());
                    return false;
                }
                String line = "";
                try {
                    loggerObj.log(Level.INFO, "reading response line");
                    while ((line = rd.readLine()) != null) {
                        System.out.println(line);
                        loggerObj.log(Level.INFO, line);
                    }
                } catch (IOException ex) {
                    loggerObj.log(Level.INFO, "cannot read the response 3" + ex.toString());
                    return false;
                }
            }
            try {
                EntityUtils.consume(resEntity);
            } catch (IOException ex) {
                loggerObj.log(Level.INFO, "cannot read the response 4" + ex.toString());
                return false;
            }
        } finally {
            try {
                response.close();
            } catch (IOException ex) {
                loggerObj.log(Level.INFO, "cannot close the response" + ex.toString());
                return false;
            }
        }
    } finally {
        try {
            httpclient.close();
        } catch (IOException ex) {
            loggerObj.log(Level.INFO, "cannot read the https clinet" + ex.toString());
            return false;
        }
    }
    return true;
}

From source file:eu.dasish.annotation.backend.rest.CachedRepresentationResource.java

/**
 * //from  www.j  a  va 2 s.c  o  m
 * @param externalId the external UUID of a cached representation.
 * @return the image-blob if the cached-representation's blob is an image file.
 * @throws IOException if logging an error fails (should be changed to sending httpResponse error message).
 */
@GET
@Produces({ "image/jpeg", "image/png" })
@Path("{cachedid: " + BackendConstants.regExpIdentifier + "}/content")
@Transactional(readOnly = true)
public BufferedImage getCachedRepresentationContent(@PathParam("cachedid") String externalId)
        throws IOException {
    Map params = new HashMap();
    try {
        InputStream result = (InputStream) (new RequestWrappers(this)).wrapRequestResource(params,
                new GetCachedRepresentationInputStream(), Resource.CACHED_REPRESENTATION, Access.READ,
                externalId);
        if (result != null) {
            ImageIO.setUseCache(false);
            try {
                BufferedImage retVal = ImageIO.read(result);
                return retVal;
            } catch (IOException e1) {
                loggerServer.info(e1.toString());

                return null;
            }
        } else {
            loggerServer.info(" The cached representation with the id " + externalId + " has null blob.");
            return null;
        }
    } catch (NotInDataBaseException e1) {
        httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e1.getMessage());
        return null;
    } catch (ForbiddenException e2) {
        httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, e2.getMessage());
        return null;
    }

}

From source file:aiai.ai.launchpad.resource.ResourceController.java

@PostMapping(value = "/resource-upload-from-file")
public String createResourceFromFile(MultipartFile file, @RequestParam(name = "code") String resourceCode,
        @RequestParam(name = "poolCode") String resourcePoolCode, final RedirectAttributes redirectAttributes) {
    File tempFile = globals.createTempFileForLaunchpad("temp-raw-file-");
    if (tempFile.exists()) {
        tempFile.delete();//from w  ww.  j av  a2s.  co  m
    }
    try {
        FileUtils.copyInputStreamToFile(file.getInputStream(), tempFile);
    } catch (IOException e) {
        redirectAttributes.addFlashAttribute("errorMessage", "#173.06 can't persist uploaded file as "
                + tempFile.getAbsolutePath() + ", error: " + e.toString());
        return "redirect:/launchpad/resources";
    }

    String originFilename = file.getOriginalFilename();
    if (originFilename == null) {
        redirectAttributes.addFlashAttribute("errorMessage", "#172.01 name of uploaded file is null");
        return "redirect:/launchpad/resources";
    }
    String code = StringUtils.isNotBlank(resourceCode) ? resourceCode : resourcePoolCode + '-' + originFilename;

    try {
        resourceService.storeInitialResource(originFilename, tempFile, code, resourcePoolCode, true,
                originFilename);
    } catch (StoreNewPartOfRawFileException e) {
        log.error("Error", e);
        redirectAttributes.addFlashAttribute("errorMessage",
                "#172.04 An error while saving data to file, " + e.toString());
        return "redirect:/launchpad/resources";
    }
    return "redirect:/launchpad/resources";
}

From source file:com.streamsets.pipeline.stage.origin.websocket.WebSocketClientSource.java

@OnWebSocketConnect
public void onConnect(Session session) {
    if (StringUtils.isNotEmpty(this.conf.requestBody)) {
        try {/*  w w  w .j  av  a 2 s  .co  m*/
            session.getRemote().sendString(this.conf.requestBody);
        } catch (IOException e) {
            errorQueue.offer(e);
            LOG.error(Errors.WEB_SOCKET_04.getMessage(), e.toString(), e);
        }
    }
}

From source file:org.hydroponics.dao.JDBCHydroponicsDaoImpl.java

@Override
public void saveImage(int grow, MultipartFile image) {
    logger.info("save image");

    try {/*ww  w.  ja v  a2  s . co m*/
        BufferedImage buffImage = ImageIO.read(image.getInputStream());
        this.jdbcTemplate.update(
                "insert into IMAGE (GROW_ID, timestamp, height, width, mimeType, thumbnail, image) values (?, ?, ?, ?, ?, ?, ?)",
                new Object[] { grow, new Timestamp(System.currentTimeMillis()), buffImage.getHeight(),
                        buffImage.getWidth(), "image/jpeg", getThumbnail(buffImage), image.getBytes() });
    } catch (IOException ex) {
        logger.severe(ex.toString());
    }
}

From source file:com.apporiented.hermesftp.server.impl.ServerRFC959Test.java

/**
 * Test case: Store, retrieve and delete.
 *///  w w w . j  a va2s  .c  o m
@Test
public void testStoreRetrieve() {
    String str;
    try {
        getClient().storeText(testFile, testText);
        str = getClient().sendAndReceive("SIZE " + testFile).trim();
        assertTrue(str.startsWith("213"));
        String[] parts = str.split(" ");
        int fileSize = Integer.parseInt(parts[1]);

        getClient().retrieveText(testFile);
        str = getClient().getTextData();
        assertEquals(testText, str);
        getClient().list(testFile);
        str = getClient().getTextData();
        assertTrue(str.length() > 0);
        getClient().appendText(testFile, testText);
        getClient().retrieveText(testFile);
        str = getClient().getTextData();
        assertEquals(testText + testText, str);
        str = getClient().sendAndReceive("SIZE " + testFile).trim();
        assertTrue(str.startsWith("213"));
        parts = str.split(" ");
        int doublefileSize = Integer.parseInt(parts[1]);
        assertEquals(fileSize * 2, doublefileSize);
        getClient().sendAndReceive("DELE " + testFile);
        getClient().list(testFile);
        str = getClient().getTextData();
        assertTrue(str.length() == 0);
    } catch (IOException e) {
        log.error(e);
        fail(e.toString());
    }
}