Java Code Examples for java.io.IOException

The following are top voted examples for showing how to use java.io.IOException. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to product more good examples.

Example 1
Project: arduino-android   File: Template.java View source code Vote up 11 votes
private String readTemplate(String resourceName)
{
	InputStream inputStream = null;
	try 
	{
		inputStream = mActivity.getAssets().open("templates/"+ resourceName + ".html");
	} 
	catch (IOException e) 
	{
		// TODO Auto-generated catch block
		e.printStackTrace();
		return "Template not found: " + resourceName;
	}
	return readTextFile(inputStream);
}
 
Example 2
Project: jumi   File: SuiteListenerEncodingTest.java View source code Vote up 8 votes
@Test
public void test_serialization_of_StackTrace_with_suppressed() {
    IOException e = new IOException("the message");
    e.addSuppressed(new IllegalArgumentException("suppressed 1"));
    e.addSuppressed(new IllegalStateException("suppressed 2"));
    StackTrace original = StackTrace.from(e);

    assertThat(roundTripStackTrace(original), is(deepEqualTo(original)));
}
 
Example 3
Project: sslcertx   File: MySQLProtocol.java View source code Vote up 6 votes
public  PrepareResult prepare(String sql) throws QueryException {
    try {
        writer.startPacket(0);
        writer.write(0x16);
        writer.write(sql.getBytes("UTF8"));
        writer.finishPacket();
        
        RawPacket rp  = packetFetcher.getRawPacket();
        checkErrorPacket(rp);
        byte b = rp.getByteBuffer().get(0);
        if (b == 0) {
            /* Prepared Statement OK */
            Reader r = new Reader(rp);
            r.readByte(); /* skip field count */
            int statementId = r.readInt();
            int numColumns = r.readShort();
            int numParams = r.readShort();
            r.readByte(); // reserved
            this.hasWarnings = r.readShort() > 0;
            MySQLColumnInformation[] params = new MySQLColumnInformation[numParams];
            if (numParams > 0) {
                for (int i = 0; i < numParams; i++) {
                    params[i] = new MySQLColumnInformation(packetFetcher.getRawPacket());
                }
                readEOFPacket();
            }
            MySQLColumnInformation[] columns = new MySQLColumnInformation[numColumns];
            if (numColumns > 0) {
                for (int i = 0; i < numColumns; i++) {
                    columns[i] = new MySQLColumnInformation(packetFetcher.getRawPacket());
                }
                readEOFPacket();
            }
            
            return new PrepareResult(statementId,columns,params);
        } else {
            throw new QueryException("Unexpected packet returned by server, first byte " + b);
        }
    } catch (IOException e) {
        throw new QueryException(e.getMessage(), -1,
                SQLExceptionMapper.SQLStates.CONNECTION_EXCEPTION.getSqlState(),
               e);
    }
}
 
Example 4
Project: netlib   File: HttpURLConnection.java View source code Vote up 6 votes
private IOException getChainedException(final IOException rememberedException) {
    try {
        final Object[] args = { rememberedException.getMessage() };
        IOException chainedException =
            java.security.AccessController.doPrivileged(
                new java.security.PrivilegedExceptionAction<IOException>() {
                    public IOException run() throws Exception {
                        return (IOException)
                            rememberedException.getClass()
                            .getConstructor(new Class[] { String.class })
                            .newInstance(args);
                    }
                });
        chainedException.initCause(rememberedException);
        return chainedException;
    } catch (Exception ignored) {
        return rememberedException;
    }
}
 
Example 5
Project: hdt-java   File: HDTGraphAssembler.java View source code Vote up 6 votes
@Override
public Model open(Assembler a, Resource root, Mode mode)
{
	String file = getStringValue(root, HDTJenaConstants.pFileName) ;
	boolean loadInMemory = Boolean.parseBoolean(getStringValue(root, HDTJenaConstants.pKeepInMemory));
	try {
		// FIXME: Read more properties. Cache config?
		HDT hdt;
		if(loadInMemory) {
			hdt = HDTManager.loadIndexedHDT(file, null);				
		} else {
			hdt = HDTManager.mapIndexedHDT(file, null);
		}
		HDTGraph graph = new HDTGraph(hdt);
		return ModelFactory.createModelForGraph(graph);
	} catch (IOException e) {
		e.printStackTrace();
		throw new AssemblerException(root, "Error reading HDT file: "+file+" / "+e.toString());
	}
}
 
Example 6
Project: phonegap-geolocation   File: HttpURLConnectionImpl.java View source code Vote up 6 votes
private boolean isRecoverable(IOException e) {
  // If the problem was a CertificateException from the X509TrustManager,
  // do not retry, we didn't have an abrupt server initiated exception.
  boolean sslFailure =
      e instanceof SSLHandshakeException && e.getCause() instanceof CertificateException;
  boolean protocolFailure = e instanceof ProtocolException;
  return !sslFailure && !protocolFailure;
}
 
Example 7
Project: wso2-synapse   File: JsonDataSourceImpl.java View source code Vote up 6 votes
public void serialize(OutputStream output, OMOutputFormat format) throws XMLStreamException {
    try {
        output.write(stream, offset, length);
    } catch (IOException e) {
        throw new OMException("Could not serialize payload. " + e.getLocalizedMessage());
    }
}
 
Example 8
Project: hadoop_ekg   File: BlockSender.java View source code Vote up 6 votes
/**
 * Converts an IOExcpetion (not subclasses) to SocketException.
 * This is typically done to indicate to upper layers that the error 
 * was a socket error rather than often more serious exceptions like 
 * disk errors.
 */
private static IOException ioeToSocketException(IOException ioe) {
  if (ioe.getClass().equals(IOException.class)) {
    // "se" could be a new class in stead of SocketException.
    IOException se = new SocketException("Original Exception : " + ioe);
    se.initCause(ioe);
    /* Change the stacktrace so that original trace is not truncated
     * when printed.*/ 
    se.setStackTrace(ioe.getStackTrace());
    return se;
  }
  // otherwise just return the same exception.
  return ioe;
}
 
Example 9
Project: OpenClinica   File: SpringServletAccess.java View source code Vote up 6 votes
public static String getPropertiesDir(ServletContext servletContext) {
  	String resource = "properties/placeholder.properties";
  	ServletContextResource scr = (ServletContextResource)getApplicationContext(servletContext).getResource(resource);
  	String absolutePath = null;
try {
	absolutePath = scr.getFile().getAbsolutePath();
} catch (IOException e) {
	throw new OpenClinicaSystemException(e.getMessage(),e.fillInStackTrace());
}
  	absolutePath = absolutePath.replaceAll("placeholder.properties", "");
  	return absolutePath;
  }
 
Example 10
Project: xapi   File: ProcessLog.java View source code Vote up 6 votes
public void log(String string, IOException e) {
  if (string != null && string.length() > 0) {
    out(string);
  }
  if (e != null) {
    out(e.toString());
    for (StackTraceElement el : e.getStackTrace()) {
      out(el.toString());
    }
  }
}
 
Example 11
Project: openmap   File: DcwRecordFile.java View source code Vote up 6 votes
/**
 * Reopen the associated input file.
 * 
 * @param seekRow the row to seek to upon reopening the file. If
 *        seekRow is invalid (less than 1), then the input stream
 *        is in an undefined location, and seekToRow (or
 *        getRow(int)) must be called before parseRow
 * @exception FormatException some error was encountered in
 *            reopening file or seeking to the desired row.
 * @see #parseRow()
 * @see #getRow(int)
 * @see #close()
 */
public synchronized void reopen(int seekRow) throws FormatException {
    try {
        if (inputFile == null) {
            inputFile = new BinaryBufferedFile(filename);
            inputFile.byteOrder(byteorder);
        }
        if (seekRow > 0) {
            seekToRow(seekRow);
        }
    } catch (IOException i) {
        throw new FormatException(i.getClass() + ": " + i.getMessage());
    }
}