List of usage examples for java.io IOException getCause
public synchronized Throwable getCause()
From source file:myproject.Model.Message.CommonMessages.DeleteDirectoryMessage.java
@Override public void executeMessage(AbstractClient client) throws Throwable { try {/*from w w w. j a va 2 s . co m*/ FileUtils.deleteDirectory(node.getValue()); Object[][] args = new Object[][] { { node } }; AbstractMessage message = new FillDeletedFilesInfoMessage(args); client.sendMessage(message); } catch (IOException e) { Object[][] args = new Object[][] { { e.getMessage(), e.getCause() } }; AbstractMessage message = new ExceptionMessage("DeleteDirectoryMessage", args); client.sendMessage(message); } }
From source file:com.hurence.logisland.serializer.BytesArraySerializer.java
public void serialize(OutputStream objectDataOutput, Record record) { Field f = record.getField(FieldDictionary.RECORD_VALUE); if (f != null && f.isSet() && f.getType().equals(FieldType.BYTES)) { try {//from w ww . j a v a 2 s . c o m objectDataOutput.write((byte[]) record.getField(FieldDictionary.RECORD_VALUE).getRawValue()); } catch (IOException ioe) { throw new RecordSerializationException(ioe.getMessage(), ioe.getCause()); } } }
From source file:org.yukung.following2ldr.command.AbstractCommand.java
public void init() { log.info("?" + getCommandName() + "???"); if (config == null) { config = new Properties(); InputStream in = getClass().getResourceAsStream(CONFIG_FILE_PATH); try {/*from w ww .j av a2 s . c o m*/ if (in == null) { throw new FileNotFoundException("?????"); } config.load(in); } catch (IOException e) { log.error(e.getMessage(), e.getCause()); } finally { try { in.close(); } catch (IOException e) { log.error(e); } } } }
From source file:ch.sourcepond.maven.plugin.jenkins.process.xslt.TransformerInputStreamTest.java
/** * @throws Exception//from w w w . java 2 s. c o m */ @Test public void verifyReadExceptionOccurred() throws Exception { final TransformerException expected = new TransformerException(ANY_MESSAGE); doThrow(expected).when(transformer).transform(input, output); try { impl.read(); fail("Exception expected"); } catch (final IOException e) { assertSame(expected, e.getCause()); } }
From source file:gobblin.runtime.cli.PublicMethodsCliObjectFactoryTest.java
@Test public void test() throws Exception { MyFactory factory = new MyFactory(); MyObject object;/*from w ww . j av a 2 s. c o m*/ try { // Try to build object with missing expected argument. object = factory.buildObject(new String[] {}, 0, false, "usage"); Assert.fail(); } catch (IOException exc) { Assert.assertTrue(exc.getCause() instanceof ArrayIndexOutOfBoundsException); // Expected } object = factory.buildObject(new String[] { "required" }, 0, false, "usage"); Assert.assertEquals(object.required, "required"); Assert.assertNull(object.string1); Assert.assertNull(object.string2); object = factory.buildObject(new String[] { "-setString1", "str1", "required" }, 0, false, "usage"); Assert.assertEquals(object.required, "required"); Assert.assertEquals(object.string1, "str1"); Assert.assertNull(object.string2); object = factory.buildObject(new String[] { "-foo", "bar", "required" }, 0, false, "usage"); Assert.assertEquals(object.required, "required"); Assert.assertEquals(object.string2, "bar"); Assert.assertNull(object.string1); object = factory.buildObject(new String[] { "-foo", "bar", "-setString1", "str1", "required" }, 0, false, "usage"); Assert.assertEquals(object.required, "required"); Assert.assertEquals(object.string2, "bar"); Assert.assertEquals(object.string1, "str1"); }
From source file:org.apache.hadoop.hbase.regionserver.TestRegionServerHostname.java
@Test(timeout = 30000) public void testInvalidRegionServerHostnameAbortsServer() throws Exception { final int NUM_MASTERS = 1; final int NUM_RS = 1; String invalidHostname = "hostAddr.invalid"; TEST_UTIL.getConfiguration().set(HRegionServer.RS_HOSTNAME_KEY, invalidHostname); try {/*from www . j ava2 s.c om*/ TEST_UTIL.startMiniCluster(NUM_MASTERS, NUM_RS); } catch (IOException ioe) { Throwable t1 = ioe.getCause(); Throwable t2 = t1.getCause(); assertTrue(t1.getMessage() + " - " + t2.getMessage(), t2.getMessage().contains("Failed resolve of " + invalidHostname) || t2.getMessage().contains("Problem binding to " + invalidHostname)); return; } finally { TEST_UTIL.shutdownMiniCluster(); } assertTrue("Failed to validate against invalid hostname", false); }
From source file:com.proofpoint.event.collector.combiner.S3CombineObjectMetadataStore.java
private CombinedGroup readMetadataFile(EventPartition eventPartition, String sizeName) { URI metadataFile = toMetadataLocation(eventPartition, sizeName); String json;//from w w w .ja v a 2s . c om try { json = new S3InputSupplier(s3Service, metadataFile).asCharSource(Charsets.UTF_8).read(); } catch (IOException e) { if (e.getCause() instanceof AmazonS3Exception) { if ("NoSuchKey".equals(((AmazonS3Exception) e.getCause()).getErrorCode())) { return null; } } throw new RuntimeException( "Could not load metadata at " + metadataFile + " file for " + eventPartition + " " + sizeName); } try { return jsonCodec.fromJson(json); } catch (IllegalArgumentException e) { throw new RuntimeException( "Metadata at " + metadataFile + " file for " + eventPartition + " " + sizeName + " is corrupt"); } }
From source file:be.solidx.hot.utils.AbstractHttpDataDeserializer.java
@Override public Object processRequestData(byte[] data, String contentType) { MediaType ct = MediaType.parseMediaType(contentType); if (LOGGER.isDebugEnabled()) LOGGER.debug("Content-type: " + contentType); Charset charset = ct.getCharSet() == null ? Charset.forName("UTF-8") : ct.getCharSet(); // Subtypes arre used because of possible encoding definitions if (ct.getSubtype().equals(MediaType.APPLICATION_OCTET_STREAM.getSubtype())) { return data; } else if (ct.getSubtype().equals(MediaType.APPLICATION_JSON.getSubtype())) { try {// w w w. ja v a2s . c o m return fromJSON(data); } catch (IOException e) { throw new RuntimeException(e.getMessage(), e.getCause()); } } else if (ct.getSubtype().equals(MediaType.APPLICATION_XML.getSubtype())) { try { return toXML(data, ct.getCharSet() == null ? Charset.forName("UTF-8") : ct.getCharSet()); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e.getCause()); } } else if (ct.getSubtype().equals(MediaType.APPLICATION_FORM_URLENCODED.getSubtype())) { String decoded; try { decoded = URLDecoder.decode(new String(data, charset), charset.toString()); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e.getCause()); } return fromFormUrlEncoded(decoded); } else { return new String(data, ct.getCharSet() == null ? Charset.forName("UTF-8") : ct.getCharSet()); } }
From source file:ch.cyberduck.core.b2.B2WriteFeatureTest.java
@Test public void testWriteChecksumFailure() throws Exception { final B2Session session = new B2Session(new Host(new B2Protocol(), new B2Protocol().getDefaultHostname(), new Credentials(System.getProperties().getProperty("b2.user"), System.getProperties().getProperty("b2.key")))); session.open(new DisabledHostKeyCallback()); session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); final Path bucket = new Path("test-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume)); final Path file = new Path(bucket, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); final TransferStatus status = new TransferStatus(); final byte[] content = RandomUtils.nextBytes(1); status.setLength(content.length);// w ww . j a v a 2s .c o m status.setChecksum(Checksum.parse("da39a3ee5e6b4b0d3255bfef95601890afd80709")); final HttpResponseOutputStream<BaseB2Response> out = new B2WriteFeature(session).write(file, status, new DisabledConnectionCallback()); IOUtils.write(content, out); try { out.close(); fail(); } catch (IOException e) { assertTrue(e.getCause() instanceof ChecksumException); } finally { session.close(); } }
From source file:org.apache.hadoop.fs.http.client.HttpFSFileSystem.java
/** * Validates the status of an <code>HttpURLConnection</code> against an * expected HTTP status code. If the current status code is not the expected * one it throws an exception with a detail message using Server side error * messages if available./*from w w w. j a va2s . c om*/ * * @param conn * the <code>HttpURLConnection</code>. * @param expected * the expected HTTP status code. * * @throws IOException * thrown if the current status code does not match the expected * one. */ private static void validateResponse(HttpURLConnection conn, int expected) throws IOException { int status = conn.getResponseCode(); if (status != expected) { try { JSONObject json = (JSONObject) jsonParse(conn); json = (JSONObject) json.get(ERROR_JSON); String message = (String) json.get(ERROR_MESSAGE_JSON); String exception = (String) json.get(ERROR_EXCEPTION_JSON); String className = (String) json.get(ERROR_CLASSNAME_JSON); try { ClassLoader cl = HttpFSFileSystem.class.getClassLoader(); Class klass = cl.loadClass(className); Constructor constr = klass.getConstructor(String.class); throw (IOException) constr.newInstance(message); } catch (IOException ex) { throw ex; } catch (Exception ex) { throw new IOException(MessageFormat.format("{0} - {1}", exception, message)); } } catch (IOException ex) { if (ex.getCause() instanceof IOException) { throw (IOException) ex.getCause(); } throw new IOException( MessageFormat.format("HTTP status [{0}], {1}", status, conn.getResponseMessage())); } } }