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.cloudera.recordbreaker.analyzer.UnknownTextSchemaDescriptor.java

/**
 * Iterate through Avro-encoded rows of the file
 *///from   w  w  w. jav a 2 s.c o m
public Iterator getIterator() {
    return new Iterator() {
        int lineno = 0;
        BufferedReader in = null;
        Object nextElt = null;
        {
            try {
                in = new BufferedReader(new InputStreamReader(dd.getRawBytes()));
                nextElt = lookahead();
            } catch (IOException iex) {
                LOG.info("iex: " + iex.toString());
                nextElt = null;
            }
        }

        public boolean hasNext() {
            return nextElt != null;
        }

        public synchronized Object next() {
            Object toReturn = nextElt;
            nextElt = lookahead();
            return toReturn;
        }

        public void remove() {
            throw new UnsupportedOperationException();
        }

        Object lookahead() {
            try {
                String str = null;
                while ((str = in.readLine()) != null) {
                    GenericContainer resultObj = typeTree.parse(str);
                    lineno++;
                    if (resultObj != null) {
                        return resultObj;
                    }
                }
                if (in != null) {
                    in.close();
                    in = null;
                }
            } catch (IOException iex) {
                iex.printStackTrace();
            }
            return null;
        }
    };
}

From source file:com.couchbase.sqoop.mapreduce.db.CouchbaseRecordReadSerializeTest.java

@Before
@Override//from  w  ww .ja v  a 2 s  .  co m
public void setUp() throws Exception {
    super.setUp();

    tappedStuff = new HashMap<String, ResponseMessage>();

    URI uri = new URI(CouchbaseUtils.CONNECT_STRING);
    String user = CouchbaseUtils.COUCHBASE_USER_NAME;
    String pass = CouchbaseUtils.COUCHBASE_USER_PASS;

    try {
        cb = new CouchbaseClient(Arrays.asList(uri), user, pass);
    } catch (IOException e) {
        LOG.error("Couldn't connect to server" + e.getMessage());
        fail(e.toString());
    }
    this.client = new TapClient(Arrays.asList(uri), user, pass);

    cb.flush();
    Thread.sleep(500);

    // set up the items we're going to deserialize
    Integer anint = new Integer(Integer.MIN_VALUE);
    cb.set(anint.toString(), 0x300, anint).get();

    Long along = new Long(Long.MAX_VALUE);
    cb.set(along.toString(), 0, along).get();

    Float afloat = new Float(Float.MAX_VALUE);
    cb.set(afloat.toString(), 0, afloat).get();

    Double doubleBase = new Double(Double.NEGATIVE_INFINITY);
    cb.set(doubleBase.toString(), 0, doubleBase).get();

    Boolean booleanBase = true;
    cb.set(booleanBase.toString(), 0, booleanBase).get();

    rightnow = new Date(); // instance, needed later
    dateText = rightnow.toString().replaceAll(" ", "_");
    cb.set(dateText, 0, rightnow).get();

    Byte byteMeSix = new Byte("6");
    cb.set(byteMeSix.toString(), 0, byteMeSix).get();

    String ourString = "hi,there";
    cb.set(ourString.toString(), 0, ourString).get();

    client.tapDump("tester");
    while (client.hasMoreMessages()) {
        ResponseMessage m = client.getNextMessage();
        if (m == null) {
            continue;
        }
        tappedStuff.put(m.getKey(), m);
    }
}

From source file:photosharing.api.oauth.CallbackDefinition.java

/**
 * processes the callback and converts the code into permanent OAuth 2.0
 * credentials/*  www.ja v a  2  s  . c  o  m*/
 * 
 * @param request
 *            the http request object
 * @param request
 *            the http response object
 */
public void run(HttpServletRequest request, HttpServletResponse response) {

    @SuppressWarnings("unused")
    Configuration config = Configuration.getInstance(request);

    HttpSession session = request.getSession(false);
    if (session != null) {
        String code = request.getParameter("code");

        // Checks to see if there is an oauth_error
        String error = request.getParameter("oauth_error");
        if (error != null) {
            // When there is an oauth_error, set SC_BAD_REQUEST
            logger.log(Level.WARNING, "Error on OAuth " + error);
            response.setStatus(HttpStatus.SC_BAD_REQUEST);

        } else {
            // Code should not be null
            if (code != null) {

                // Accesses the OAuth 20 Data
                OAuth20Handler handler = OAuth20Handler.getInstance();
                OAuth20Data oauthData = null;
                try {
                    logger.info("call to access token");
                    oauthData = handler.getAccessToken(code);
                } catch (IOException e1) {
                    logger.log(Level.WARNING, "IOException on getAccessToken  " + e1.toString());
                }

                // Checks the OAuth 2.0 data
                if (oauthData != null) {
                    // When there is credential data persist in the session
                    // and return SC_OK 
                    session.setAttribute(OAuth20Handler.CREDENTIALS, oauthData);

                    // Closes the Popup window
                    try {
                        response.setStatus(HttpStatus.SC_OK);
                        response.setContentType("text/html");
                        PrintWriter out = response.getWriter();
                        out.println("<html><body onload=\"javascript:window.close()\"></body></html>");
                    } catch (IOException e) {
                        logger.log(Level.WARNING, "IOException on Redirect " + e.toString());
                    }

                } else {
                    // OAuth Data
                    logger.log(Level.WARNING, "Error handling the oauth data");
                    response.setStatus(HttpStatus.SC_BAD_REQUEST);
                }
            } else {
                // When there is no code, set SC_BAD_REQUEST
                logger.log(Level.WARNING, "No Code passed into the URL " + request.getPathInfo());
                response.setStatus(HttpStatus.SC_BAD_REQUEST);
            }
        }

    } else {
        // When there is no session, set SC_BAD_REQUEST
        logger.log(Level.WARNING, "Invalid Session");
        response.setStatus(HttpStatus.SC_BAD_REQUEST);
    }

}

From source file:org.londonsburning.proxy.ProxyPrinter.java

/**
 * <p>/*from  w ww. ja v  a  2s.  com*/
 * writeDeck.
 * </p>
 *
 * @param deck           a String
 * @param file           a File
 * @param skipBasicLands Skip Basic Lands
 */
private void generateHtml(final Deck deck, final File file, final boolean skipBasicLands) {
    try {
        final BufferedWriter htmlOutput = new BufferedWriter(new FileWriter(file));

        Template template;

        final Configuration cfg = new Configuration();
        cfg.setClassForTemplateLoading(deck.getClass(), "/");
        cfg.setObjectWrapper(new DefaultObjectWrapper());
        template = cfg.getTemplate(this.proxyConfiguration.getOutputTemplate());

        final TreeMap<String, Object> root = new TreeMap<String, Object>();
        root.put("title", deck.getDeckName());
        final List<String> list = new ArrayList<String>();
        for (final String cardName : deck.getCardList().keySet()) {
            for (int i = 0; i <= (deck.getCardList().get(cardName) - 1); i++) {
                if (!this.proxyConfiguration.getBasicLandNames().contains(cardName) || !skipBasicLands) {
                    list.add(getURL(cardName));
                }
            }
        }

        final LinkedHashMap<String, Integer> map = deck.getCardList();
        root.put("urls", list);
        root.put("cardBorder", this.proxyConfiguration.getCard().getCardBorder());
        root.put("cardHeight", Math.round(this.proxyConfiguration.getCard().getCardHeight()
                * this.proxyConfiguration.getCard().getCardScale()));
        root.put("cardWidth", Math.round(this.proxyConfiguration.getCard().getCardWidth()
                * this.proxyConfiguration.getCard().getCardScale()));
        root.put("cardListWidth",
                this.proxyConfiguration.getCard().getCardWidth() - this.proxyConfiguration.getCardListWidth());
        root.put("cardList", map);
        root.put("numberOfCards", deck.getNumberOfCards());

        /* Merge data-model with template */
        template.process(root, htmlOutput);
        htmlOutput.flush();
        htmlOutput.close();
    } catch (final IOException e) {
        logger.debug(e.toString());
    } catch (final TemplateException e) {
        logger.debug(e.toString());
    } catch (final URISyntaxException e) {
        logger.debug(e.toString());
    } catch (final InterruptedException e) {
        logger.debug(e.toString());
    }
}

From source file:com.streamsets.pipeline.stage.destination.recordstolocalfilesystem.RecordsToLocalFileSystemTarget.java

@Override
public void destroy() {
    try {//from  w  ww  .j a  va2s.c  o m
        //closing file and rotating.
        rotate(false);
    } catch (IOException ex) {
        LOG.warn("Could not do rotation on destroy(): {}", ex.toString(), ex);
    }
    IOUtils.closeQuietly(generator);
    IOUtils.closeQuietly(countingOutputStream);
    super.destroy();
}

From source file:com.navinfo.flume.sink.FileKafkaSink.java

private synchronized void demoFileWrite(final String fileName, final byte[] contents) throws IOException {
    Preconditions.checkNotNull(fileName, "Provided file name for writing must NOT be null.");
    Preconditions.checkNotNull(contents, "Unable to write null contents.");
    final File newFile = new File(fileName);
    try {/*from w w w.j  a  v  a2  s.  com*/
        Files.write(contents, newFile);
    } catch (IOException fileIoEx) {
        logger.error("ERROR trying to write to file '" + fileName + "' - " + fileIoEx.toString());
        throw (fileIoEx);
    }

}

From source file:multichain.command.builders.QueryBuilderCommon.java

/**
 * //from   w w  w .j  a  v a  2s .  c  o  m
 * @param command
 * @param parameters
 * 
 * @return
 * 
 *       example :
 *         MultichainQueryBuidlder.executeProcess(MultichainCommand
 *         .SENDTOADDRESS,"1EyXuq2JVrj4E3CpM9iNGNSqBpZ2iTPdwGKgvf
 *         {\"rdcoin\":0.01}"
 * @throws MultichainException
 */
protected Object execute(CommandEnum command, Object... parameters) throws MultichainException {

    if (httpclient != null && httppost != null) {
        try {
            // Generate Mapping of calling arguments
            Map<String, Object> entityValues = prepareMap(this.queryParameters, command, parameters);
            // Generate the entity and initialize request
            StringEntity rpcEntity = prepareRpcEntity(entityValues);
            httppost.setEntity(rpcEntity);
            // Execute the request and get the answer
            return executeRequest();

        } catch (IOException e) {
            e.printStackTrace();
            throw new MultichainException(null, e.toString());
        }
    } else {
        throw new MultichainException("Initialization Problem",
                "MultiChainCommand not initialized, please specify ip, port, user and pwd !");

    }
}

From source file:com.couchbase.sqoop.manager.CouchbaseManagerTest.java

private void runCouchbaseTest(HashMap<String, String> expectedMap) throws IOException {
    Path warehousePath = new Path(this.getWarehouseDir());
    Path tablePath = new Path(warehousePath, TABLE_NAME);
    Path filePath = new Path(tablePath, "part-m-00000");

    File tableFile = new File(tablePath.toString());
    if (tableFile.exists() && tableFile.isDirectory()) {
        // remove the directory before running the import.
        FileListing.recursiveDeleteDir(tableFile);
    }/*from   w w w  . jav  a  2  s . co  m*/

    String[] argv = getArgv();
    try {
        runImport(argv);
    } catch (IOException ioe) {
        LOG.error("Got IOException during import: " + ioe.toString());
        ioe.printStackTrace();
        fail(ioe.toString());
    }

    File f = new File(filePath.toString());
    assertTrue("Could not find imported data file", f.exists());
    BufferedReader r = null;
    try {
        // Read through the file and make sure it's all there.
        r = new BufferedReader(new InputStreamReader(new FileInputStream(f)));
        String line;
        int records = 0;
        while ((line = r.readLine()) != null) {
            compareRecords(expectedMap, line);
            records++;
        }
        if (records < NUM_RECORDS) {
            fail("Not everything was imported. Got " + records + "/" + NUM_RECORDS + " records.");
        }
    } catch (IOException ioe) {
        LOG.error("Got IOException verifying results: " + ioe.toString());
        ioe.printStackTrace();
        fail(ioe.toString());
    } finally {
        IOUtils.closeStream(r);
    }
}

From source file:ws.util.AbstractJSONCoder.java

@Override
public boolean willDecode(String json) {
    //            logger.log(Level.INFO, new StringBuilder()
    //                  .append("[coder] will decoding..")
    //                  .toString());
    try {//w  ww  .  j a v  a 2 s  . c o m
        JSON.std.beanFrom(type, json);
        //                  logger.log(Level.INFO, new StringBuilder()
        //                        .append("[coder] OK.. return true")
        //                        .toString());
        return true;
    } catch (IOException e) {
        logger.log(Level.SEVERE, new StringBuilder().append("[coder] NG.. return false").toString());
        logger.log(Level.SEVERE, e.toString());
        return false;
    }

}

From source file:com.ewcms.content.resource.web.ResourceAction.java

/**
 * ?/*from   w  w w. j  a  v a  2 s .co m*/
 */
public void receive() {
    try {
        logger.debug("Resource name is {} and type is {}", myUploadFileName, type);
        Resource.Type resType = Resource.Type.valueOf(StringUtils.upperCase(type));
        Resource resource;
        if (isNewAdd()) {
            resource = resourceFac.uploadResource(myUpload, myUploadFileName, resType);
        } else {
            resource = resourceFac.updateResource(id, myUpload, myUploadFileName, resType);
        }
        renderSuccess(resource);
    } catch (IOException e) {
        logger.error("Upload resource is error:{}", e);
        renderError(e.toString());
    }
}