Java Examples for java.io.IOException

The following java examples will help you to understand the usage of java.io.IOException. These source code samples are taken from different open source projects.

Example 1
Project: IKVM.NET-cvs-clone-master  File: InputStreamWrapper.java View source code
public int read() throws java.io.IOException {
    try {
        if (false)
            throw new cli.System.IO.IOException();
        if (false)
            throw new cli.System.ObjectDisposedException(null);
        int i = stream.ReadByte();
        if (i == -1) {
            atEOF = true;
        }
        return i;
    } catch (cli.System.IO.IOException x) {
        java.io.IOException ex = new java.io.IOException();
        ex.initCause(x);
        throw ex;
    } catch (cli.System.ObjectDisposedException x) {
        java.io.IOException ex = new java.io.IOException();
        ex.initCause(x);
        throw ex;
    }
}
Example 2
Project: eclipse.jdt.ui-master  File: Catch2.java View source code
public void foo(int a, IOException second) throws Exception {
    try {
        if (a < 10)
            throw new FileNotFoundException();
        else if (a < 20)
            throw new InterruptedIOException();
    } catch (FileNotFoundExceptionInterruptedIOException |  ex) {
        second.printStackTrace();
    }
}
Example 3
Project: ARTPart-master  File: IOExceptionTest.java View source code
/**
     * java.io.IOException#IOException(java.lang.String,
     *java.lang.Throwable)
     * @since 1.6
     */
public void test_ConstructorLString_LThrowable() {
    // Test for constructor java.io.IOException(java.lang.String, java.lang.Throwable)
    IOException ioException = new IOException("A dummy IOException", //$NON-NLS-1$//$NON-NLS-2$
    new Throwable("A dummy Throwable"));
    //$NON-NLS-1$
    assertEquals("A dummy IOException", ioException.getMessage());
    try {
        throw new IOException("A dummy error", //$NON-NLS-1$ //$NON-NLS-2$
        new Throwable("Some error message"));
    } catch (IOException e) {
        return;
    } catch (Exception e) {
        fail("Exception during IOException test" + e.toString());
    }
    //$NON-NLS-1$
    fail("Failed to generate exception");
}
Example 4
Project: android-sdk-sources-for-api-level-23-master  File: IOExceptionTest.java View source code
/**
     * java.io.IOException#IOException(java.lang.String,
     *java.lang.Throwable)
     * @since 1.6
     */
public void test_ConstructorLString_LThrowable() {
    // Test for constructor java.io.IOException(java.lang.String, java.lang.Throwable)
    IOException ioException = new IOException("A dummy IOException", //$NON-NLS-1$//$NON-NLS-2$
    new Throwable("A dummy Throwable"));
    //$NON-NLS-1$
    assertEquals("A dummy IOException", ioException.getMessage());
    try {
        throw new IOException("A dummy error", //$NON-NLS-1$ //$NON-NLS-2$
        new Throwable("Some error message"));
    } catch (IOException e) {
        return;
    } catch (Exception e) {
        fail("Exception during IOException test" + e.toString());
    }
    //$NON-NLS-1$
    fail("Failed to generate exception");
}
Example 5
Project: ikvm-openjdk-master  File: WebRowSetXmlWriter.java View source code
/**
     *
     *
     * @exception SQLException if a database access error occurs
     */
private void writeProperties(WebRowSet caller) throws java.io.IOException {
    beginSection("properties");
    try {
        propString("command", processSpecialCharacters(caller.getCommand()));
        propInteger("concurrency", caller.getConcurrency());
        propString("datasource", caller.getDataSourceName());
        propBoolean("escape-processing", caller.getEscapeProcessing());
        try {
            propInteger("fetch-direction", caller.getFetchDirection());
        } catch (SQLException sqle) {
        }
        propInteger("fetch-size", caller.getFetchSize());
        propInteger("isolation-level", caller.getTransactionIsolation());
        beginSection("key-columns");
        int[] kc = caller.getKeyColumns();
        for (int i = 0; kc != null && i < kc.length; i++) propInteger("column", kc[i]);
        endSection("key-columns");
        //Changed to beginSection and endSection for maps for proper indentation
        beginSection("map");
        java.util.Map typeMap = caller.getTypeMap();
        if (typeMap != null) {
            Iterator i = typeMap.keySet().iterator();
            Class c;
            String type;
            while (i.hasNext()) {
                type = (String) i.next();
                c = (Class) typeMap.get(type);
                propString("type", type);
                propString("class", c.getName());
            }
        }
        endSection("map");
        propInteger("max-field-size", caller.getMaxFieldSize());
        propInteger("max-rows", caller.getMaxRows());
        propInteger("query-timeout", caller.getQueryTimeout());
        propBoolean("read-only", caller.isReadOnly());
        int itype = caller.getType();
        String strType = "";
        if (itype == 1003) {
            strType = "ResultSet.TYPE_FORWARD_ONLY";
        } else if (itype == 1004) {
            strType = "ResultSet.TYPE_SCROLL_INSENSITIVE";
        } else if (itype == 1005) {
            strType = "ResultSet.TYPE_SCROLL_SENSITIVE";
        }
        propString("rowset-type", strType);
        propBoolean("show-deleted", caller.getShowDeleted());
        propString("table-name", caller.getTableName());
        propString("url", caller.getUrl());
        beginSection("sync-provider");
        // Remove the string after "@xxxx"
        // before writing it to the xml file.
        String strProviderInstance = (caller.getSyncProvider()).toString();
        String strProvider = strProviderInstance.substring(0, (caller.getSyncProvider()).toString().indexOf("@"));
        propString("sync-provider-name", strProvider);
        propString("sync-provider-vendor", "Sun Microsystems Inc.");
        propString("sync-provider-version", "1.0");
        propInteger("sync-provider-grade", caller.getSyncProvider().getProviderGrade());
        propInteger("data-source-lock", caller.getSyncProvider().getDataSourceLock());
        endSection("sync-provider");
    } catch (SQLException ex) {
        throw new java.io.IOException(MessageFormat.format(resBundle.handleGetObject("wrsxmlwriter.sqlex").toString(), ex.getMessage()));
    }
    endSection("properties");
}
Example 6
Project: JDK-master  File: RMIConnectionImpl_Stub.java View source code
// methods from remote interfaces
// implementation of addNotificationListener(ObjectName, ObjectName, MarshalledObject, MarshalledObject, Subject)
public void addNotificationListener(javax.management.ObjectName $param_ObjectName_1, javax.management.ObjectName $param_ObjectName_2, java.rmi.MarshalledObject $param_MarshalledObject_3, java.rmi.MarshalledObject $param_MarshalledObject_4, javax.security.auth.Subject $param_Subject_5) throws java.io.IOException, javax.management.InstanceNotFoundException {
    try {
        ref.invoke(this, $method_addNotificationListener_0, new java.lang.Object[] { $param_ObjectName_1, $param_ObjectName_2, $param_MarshalledObject_3, $param_MarshalledObject_4, $param_Subject_5 }, -8578317696269497109L);
    } catch (java.lang.RuntimeException e) {
        throw e;
    } catch (java.io.IOException e) {
        throw e;
    } catch (javax.management.InstanceNotFoundException e) {
        throw e;
    } catch (java.lang.Exception e) {
        throw new java.rmi.UnexpectedException("undeclared checked exception", e);
    }
}
Example 7
Project: openjdk8-jdk-master  File: WebRowSetXmlWriter.java View source code
/**
     *
     *
     * @exception SQLException if a database access error occurs
     */
private void writeProperties(WebRowSet caller) throws java.io.IOException {
    beginSection("properties");
    try {
        propString("command", processSpecialCharacters(caller.getCommand()));
        propInteger("concurrency", caller.getConcurrency());
        propString("datasource", caller.getDataSourceName());
        propBoolean("escape-processing", caller.getEscapeProcessing());
        try {
            propInteger("fetch-direction", caller.getFetchDirection());
        } catch (SQLException sqle) {
        }
        propInteger("fetch-size", caller.getFetchSize());
        propInteger("isolation-level", caller.getTransactionIsolation());
        beginSection("key-columns");
        int[] kc = caller.getKeyColumns();
        for (int i = 0; kc != null && i < kc.length; i++) propInteger("column", kc[i]);
        endSection("key-columns");
        //Changed to beginSection and endSection for maps for proper indentation
        beginSection("map");
        Map<String, Class<?>> typeMap = caller.getTypeMap();
        if (typeMap != null) {
            for (Map.Entry<String, Class<?>> mm : typeMap.entrySet()) {
                propString("type", mm.getKey());
                propString("class", mm.getValue().getName());
            }
        }
        endSection("map");
        propInteger("max-field-size", caller.getMaxFieldSize());
        propInteger("max-rows", caller.getMaxRows());
        propInteger("query-timeout", caller.getQueryTimeout());
        propBoolean("read-only", caller.isReadOnly());
        int itype = caller.getType();
        String strType = "";
        if (itype == 1003) {
            strType = "ResultSet.TYPE_FORWARD_ONLY";
        } else if (itype == 1004) {
            strType = "ResultSet.TYPE_SCROLL_INSENSITIVE";
        } else if (itype == 1005) {
            strType = "ResultSet.TYPE_SCROLL_SENSITIVE";
        }
        propString("rowset-type", strType);
        propBoolean("show-deleted", caller.getShowDeleted());
        propString("table-name", caller.getTableName());
        propString("url", caller.getUrl());
        beginSection("sync-provider");
        // Remove the string after "@xxxx"
        // before writing it to the xml file.
        String strProviderInstance = (caller.getSyncProvider()).toString();
        String strProvider = strProviderInstance.substring(0, (caller.getSyncProvider()).toString().indexOf("@"));
        propString("sync-provider-name", strProvider);
        propString("sync-provider-vendor", "Oracle Corporation");
        propString("sync-provider-version", "1.0");
        propInteger("sync-provider-grade", caller.getSyncProvider().getProviderGrade());
        propInteger("data-source-lock", caller.getSyncProvider().getDataSourceLock());
        endSection("sync-provider");
    } catch (SQLException ex) {
        throw new java.io.IOException(MessageFormat.format(resBundle.handleGetObject("wrsxmlwriter.sqlex").toString(), ex.getMessage()));
    }
    endSection("properties");
}
Example 8
Project: openjdk-master  File: UserInputTest.java View source code
public void testClose() {
    setInput(new InputStream() {

        private final byte[] data = new byte[] { 0, 1, 2 };

        private int cursor;

        @Override
        public int read() throws IOException {
            if (cursor < data.length) {
                return data[cursor++];
            } else {
                return -1;
            }
        }
    });
    assertEval("int read;", "0");
    assertEval("System.in.read();", "0");
    assertEval("System.in.read();", "1");
    assertEval("System.in.read();", "2");
    assertEval("System.in.read();", "-1");
    assertEval("System.in.read();", "-1");
    assertEval("System.in.read();", "-1");
}
Example 9
Project: jdk7u-jdk-master  File: WebRowSetXmlWriter.java View source code
/**
     *
     *
     * @exception SQLException if a database access error occurs
     */
private void writeProperties(WebRowSet caller) throws java.io.IOException {
    beginSection("properties");
    try {
        propString("command", processSpecialCharacters(caller.getCommand()));
        propInteger("concurrency", caller.getConcurrency());
        propString("datasource", caller.getDataSourceName());
        propBoolean("escape-processing", caller.getEscapeProcessing());
        try {
            propInteger("fetch-direction", caller.getFetchDirection());
        } catch (SQLException sqle) {
        }
        propInteger("fetch-size", caller.getFetchSize());
        propInteger("isolation-level", caller.getTransactionIsolation());
        beginSection("key-columns");
        int[] kc = caller.getKeyColumns();
        for (int i = 0; kc != null && i < kc.length; i++) propInteger("column", kc[i]);
        endSection("key-columns");
        //Changed to beginSection and endSection for maps for proper indentation
        beginSection("map");
        java.util.Map typeMap = caller.getTypeMap();
        if (typeMap != null) {
            Iterator i = typeMap.keySet().iterator();
            Class c;
            String type;
            while (i.hasNext()) {
                type = (String) i.next();
                c = (Class) typeMap.get(type);
                propString("type", type);
                propString("class", c.getName());
            }
        }
        endSection("map");
        propInteger("max-field-size", caller.getMaxFieldSize());
        propInteger("max-rows", caller.getMaxRows());
        propInteger("query-timeout", caller.getQueryTimeout());
        propBoolean("read-only", caller.isReadOnly());
        int itype = caller.getType();
        String strType = "";
        if (itype == 1003) {
            strType = "ResultSet.TYPE_FORWARD_ONLY";
        } else if (itype == 1004) {
            strType = "ResultSet.TYPE_SCROLL_INSENSITIVE";
        } else if (itype == 1005) {
            strType = "ResultSet.TYPE_SCROLL_SENSITIVE";
        }
        propString("rowset-type", strType);
        propBoolean("show-deleted", caller.getShowDeleted());
        propString("table-name", caller.getTableName());
        propString("url", caller.getUrl());
        beginSection("sync-provider");
        // Remove the string after "@xxxx"
        // before writing it to the xml file.
        String strProviderInstance = (caller.getSyncProvider()).toString();
        String strProvider = strProviderInstance.substring(0, (caller.getSyncProvider()).toString().indexOf("@"));
        propString("sync-provider-name", strProvider);
        propString("sync-provider-vendor", "Oracle Corporation");
        propString("sync-provider-version", "1.0");
        propInteger("sync-provider-grade", caller.getSyncProvider().getProviderGrade());
        propInteger("data-source-lock", caller.getSyncProvider().getDataSourceLock());
        endSection("sync-provider");
    } catch (SQLException ex) {
        throw new java.io.IOException(MessageFormat.format(resBundle.handleGetObject("wrsxmlwriter.sqlex").toString(), ex.getMessage()));
    }
    endSection("properties");
}
Example 10
Project: classlib6-master  File: WebRowSetXmlWriter.java View source code
/**
     *
     *
     * @exception SQLException if a database access error occurs
     */
private void writeProperties(WebRowSet caller) throws java.io.IOException {
    beginSection("properties");
    try {
        propString("command", processSpecialCharacters(caller.getCommand()));
        propInteger("concurrency", caller.getConcurrency());
        propString("datasource", caller.getDataSourceName());
        propBoolean("escape-processing", caller.getEscapeProcessing());
        try {
            propInteger("fetch-direction", caller.getFetchDirection());
        } catch (SQLException sqle) {
        }
        propInteger("fetch-size", caller.getFetchSize());
        propInteger("isolation-level", caller.getTransactionIsolation());
        beginSection("key-columns");
        int[] kc = caller.getKeyColumns();
        for (int i = 0; kc != null && i < kc.length; i++) propInteger("column", kc[i]);
        endSection("key-columns");
        //Changed to beginSection and endSection for maps for proper indentation
        beginSection("map");
        java.util.Map typeMap = caller.getTypeMap();
        if (typeMap != null) {
            Iterator i = typeMap.keySet().iterator();
            Class c;
            String type;
            while (i.hasNext()) {
                type = (String) i.next();
                c = (Class) typeMap.get(type);
                propString("type", type);
                propString("class", c.getName());
            }
        }
        endSection("map");
        propInteger("max-field-size", caller.getMaxFieldSize());
        propInteger("max-rows", caller.getMaxRows());
        propInteger("query-timeout", caller.getQueryTimeout());
        propBoolean("read-only", caller.isReadOnly());
        int itype = caller.getType();
        String strType = "";
        if (itype == 1003) {
            strType = "ResultSet.TYPE_FORWARD_ONLY";
        } else if (itype == 1004) {
            strType = "ResultSet.TYPE_SCROLL_INSENSITIVE";
        } else if (itype == 1005) {
            strType = "ResultSet.TYPE_SCROLL_SENSITIVE";
        }
        propString("rowset-type", strType);
        propBoolean("show-deleted", caller.getShowDeleted());
        propString("table-name", caller.getTableName());
        propString("url", caller.getUrl());
        beginSection("sync-provider");
        // Remove the string after "@xxxx" 
        // before writing it to the xml file.
        String strProviderInstance = (caller.getSyncProvider()).toString();
        String strProvider = strProviderInstance.substring(0, (caller.getSyncProvider()).toString().indexOf("@"));
        propString("sync-provider-name", strProvider);
        propString("sync-provider-vendor", "Sun Microsystems Inc.");
        propString("sync-provider-version", "1.0");
        propInteger("sync-provider-grade", caller.getSyncProvider().getProviderGrade());
        propInteger("data-source-lock", caller.getSyncProvider().getDataSourceLock());
        endSection("sync-provider");
    } catch (SQLException ex) {
        throw new java.io.IOException(MessageFormat.format(resBundle.handleGetObject("wrsxmlwriter.sqlex").toString(), ex.getMessage()));
    }
    endSection("properties");
}
Example 11
Project: ManagedRuntimeInitiative-master  File: WebRowSetXmlWriter.java View source code
/**
     *
     *
     * @exception SQLException if a database access error occurs
     */
private void writeProperties(WebRowSet caller) throws java.io.IOException {
    beginSection("properties");
    try {
        propString("command", processSpecialCharacters(caller.getCommand()));
        propInteger("concurrency", caller.getConcurrency());
        propString("datasource", caller.getDataSourceName());
        propBoolean("escape-processing", caller.getEscapeProcessing());
        try {
            propInteger("fetch-direction", caller.getFetchDirection());
        } catch (SQLException sqle) {
        }
        propInteger("fetch-size", caller.getFetchSize());
        propInteger("isolation-level", caller.getTransactionIsolation());
        beginSection("key-columns");
        int[] kc = caller.getKeyColumns();
        for (int i = 0; kc != null && i < kc.length; i++) propInteger("column", kc[i]);
        endSection("key-columns");
        //Changed to beginSection and endSection for maps for proper indentation
        beginSection("map");
        java.util.Map typeMap = caller.getTypeMap();
        if (typeMap != null) {
            Iterator i = typeMap.keySet().iterator();
            Class c;
            String type;
            while (i.hasNext()) {
                type = (String) i.next();
                c = (Class) typeMap.get(type);
                propString("type", type);
                propString("class", c.getName());
            }
        }
        endSection("map");
        propInteger("max-field-size", caller.getMaxFieldSize());
        propInteger("max-rows", caller.getMaxRows());
        propInteger("query-timeout", caller.getQueryTimeout());
        propBoolean("read-only", caller.isReadOnly());
        int itype = caller.getType();
        String strType = "";
        if (itype == 1003) {
            strType = "ResultSet.TYPE_FORWARD_ONLY";
        } else if (itype == 1004) {
            strType = "ResultSet.TYPE_SCROLL_INSENSITIVE";
        } else if (itype == 1005) {
            strType = "ResultSet.TYPE_SCROLL_SENSITIVE";
        }
        propString("rowset-type", strType);
        propBoolean("show-deleted", caller.getShowDeleted());
        propString("table-name", caller.getTableName());
        propString("url", caller.getUrl());
        beginSection("sync-provider");
        // Remove the string after "@xxxx"
        // before writing it to the xml file.
        String strProviderInstance = (caller.getSyncProvider()).toString();
        String strProvider = strProviderInstance.substring(0, (caller.getSyncProvider()).toString().indexOf("@"));
        propString("sync-provider-name", strProvider);
        propString("sync-provider-vendor", "Sun Microsystems Inc.");
        propString("sync-provider-version", "1.0");
        propInteger("sync-provider-grade", caller.getSyncProvider().getProviderGrade());
        propInteger("data-source-lock", caller.getSyncProvider().getDataSourceLock());
        endSection("sync-provider");
    } catch (SQLException ex) {
        throw new java.io.IOException(MessageFormat.format(resBundle.handleGetObject("wrsxmlwriter.sqlex").toString(), ex.getMessage()));
    }
    endSection("properties");
}
Example 12
Project: schach-master  File: ListReader.java View source code
public static ArrayList<String> loadStrings(File aFile) {
    ArrayList<String> pVec = new ArrayList<String>();
    if (!aFile.exists())
        return pVec;
    try {
        BufferedReader pReader = new BufferedReader(new FileReader(aFile));
        String pLine;
        while ((pLine = pReader.readLine()) != null) {
            pLine = pLine.trim();
            if (pLine.startsWith("#") || pLine.equals(""))
                continue;
            pVec.add(pLine);
        }
        pReader.close();
    } catch (IOException aE) {
        aE.printStackTrace();
    }
    return pVec;
}
Example 13
Project: jeboorker-master  File: LineReaderTest.java View source code
public void testLineReader() {
    StringBuilder b = new StringBuilder("erste\nzweite\ndritte");
    LineReader reader = new LineReader(new ByteArrayInputStream(b.toString().getBytes()));
    StringBuilder result = new StringBuilder();
    try {
        reader.readLine(result);
        assertEquals("erste", result.toString());
        reader.readLine(result);
        assertEquals("erstezweite", result.toString());
        reader.readLine(result);
        assertEquals("erstezweitedritte", result.toString());
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Example 14
Project: jeql-master  File: DbfFile.java View source code
/**
            * Fetches a part column of Integers from the database file.
            * @param int col - the column to fetch
            * @param int start - the row to start fetching from
            * @param int end - the row to stop fetching at.
            * @exception java.io.IOException - on read error
            * @exception DbfFileException - column is not an Integer.
            */
public Integer[] getIntegerCol(int col, int start, int end) throws java.io.IOException, DbfFileException {
    Integer[] column = new Integer[end - start];
    String record = new String();
    StringBuffer sb = new StringBuffer(numfields);
    int k = 0;
    int i = 0;
    if (col >= numfields) {
        throw new DbfFileException("DbFi>No Such Column in file: " + col);
    }
    if (fielddef[col].fieldtype != 'N') {
        throw new DbfFileException("DbFi>Column " + col + " is not Integer");
    }
    // move to start of data
    try {
        rFile.seek(data_offset + (rec_size * start));
        for (i = start; i < end; i++) {
            sb.setLength(0);
            for (k = 0; k < rec_size; k++) sb.append((char) rFile.readUnsignedByte());
            record = sb.toString();
            try {
                column[i - start] = new Integer(record.substring(fielddef[col].fieldstart, fielddef[col].fieldstart + fielddef[col].fieldlen));
            } catch (java.lang.NumberFormatException e) {
                column[i - start] = new Integer(0);
            }
        }
    } catch (java.io.EOFException e) {
        System.err.println("DbFi>" + e);
        System.err.println("DbFi>record " + i + " byte " + k + " file pos " + rFile.getFilePointer());
    } catch (java.io.IOException e) {
        System.err.println("DbFi>" + e);
        System.err.println("DbFi>record " + i + " byte " + k + " file pos " + rFile.getFilePointer());
    }
    return column;
}
Example 15
Project: gpu-garbage-collection-master  File: TestSerialization.java View source code
public static void main(String[] args) throws Exception {
    //Uncomment when need to generate serialized data from jdk again
    /*
    try {
      final ObjectOutputStream output = new ObjectOutputStream(new java.io.FileOutputStream("MySerializationData.dat"));
      output.writeObject(new SerializationData());
      output.close();
    } catch (java.io.IOException e) {
      e.printStackTrace(System.out);
    }
*/
    final byte[] data = loadData();
    try {
        final ObjectInputStream input = new ObjectInputStream(new ByteArrayInputStream(data));
        System.out.println("Attemping read");
        final SerializationData ts = (SerializationData) input.readObject();
        System.out.println("Existing serialization read");
        System.out.println(ts);
    } catch (java.io.IOException e) {
        e.printStackTrace(System.out);
    } catch (ClassNotFoundException e) {
        e.printStackTrace(System.out);
    }
    byte[] bytes = new byte[0];
    try {
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        final ObjectOutputStream output = new ObjectOutputStream(baos);
        System.out.println("Attemping write");
        SerializationData sd = new SerializationData();
        sd.jitter();
        output.writeObject(sd);
        output.flush();
        output.close();
        bytes = baos.toByteArray();
        System.out.println("write success. Checking consistency of data written ...");
        System.out.println("actual.length (" + bytes.length + ") vs expected.length (" + data.length);
        for (int i = 0; i < data.length && i < bytes.length; i++) {
            if (data[i] != bytes[i]) {
                System.out.println("data differs at " + i);
                break;
            }
        }
    } catch (java.io.IOException e) {
        e.printStackTrace(System.out);
    }
    try {
        final ObjectInputStream input = new ObjectInputStream(new ByteArrayInputStream(bytes));
        System.out.println("Attemping read of output data");
        final SerializationData ts = (SerializationData) input.readObject();
        System.out.println("Existing serialization read");
        System.out.println(ts);
    } catch (java.io.IOException e) {
        e.printStackTrace(System.out);
    } catch (ClassNotFoundException e) {
        e.printStackTrace(System.out);
    }
}
Example 16
Project: android_packages_apps-master  File: NdefPushProtocol.java View source code
public byte[] toByteArray() {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream(1024);
    DataOutputStream output = new DataOutputStream(buffer);
    try {
        output.writeByte(VERSION);
        output.writeInt(mNumMessages);
        for (int i = 0; i < mNumMessages; i++) {
            output.writeByte(mActions[i]);
            byte[] bytes = mMessages[i].toByteArray();
            output.writeInt(bytes.length);
            output.write(bytes);
        }
    } catch (java.io.IOException e) {
        return null;
    }
    return buffer.toByteArray();
}
Example 17
Project: sonar-java-master  File: InterruptedExceptionCheck.java View source code
public void run() throws InterruptedException {
    try {
        while (true) {
        // do stuff
        }
    } catch (InterruptedException e) {
        LOGGER.log(Level.WARN, "Interrupted!", e);
        throw e;
    } catch (// Noncompliant {{Either re-interrupt this method or rethrow the "InterruptedException".}}
    InterruptedException // Noncompliant {{Either re-interrupt this method or rethrow the "InterruptedException".}}
    e) {
        LOGGER.log(Level.WARN, "Interrupted!", e);
        throw new java.io.IOException();
    } catch (// Noncompliant {{Either re-interrupt this method or rethrow the "InterruptedException".}}
    InterruptedException // Noncompliant {{Either re-interrupt this method or rethrow the "InterruptedException".}}
    e) {
        LOGGER.log(Level.WARN, "Interrupted!", e);
        Exception e1 = new Exception();
        throw e1;
    } catch (// Noncompliant {{Either re-interrupt this method or rethrow the "InterruptedException".}}
    InterruptedException // Noncompliant {{Either re-interrupt this method or rethrow the "InterruptedException".}}
    e) {
        LOGGER.log(Level.WARN, "Interrupted!", e);
        throw new IllegalStateException("foo", e);
    }
}
Example 18
Project: oobd-master  File: ASN1Null.java View source code
public static ASN1Null getInstance(Object o) {
    if (o instanceof ASN1Null) {
        return (ASN1Null) o;
    }
    if (o != null) {
        try {
            return ASN1Null.getInstance(ASN1Primitive.fromByteArray((byte[]) o));
        } catch (IOException e) {
            throw new IllegalArgumentException("failed to construct NULL from byte[]: " + e.getMessage());
        } catch (ClassCastException e) {
            throw new IllegalArgumentException("unknown object in getInstance(): " + o.getClass().getName());
        }
    }
    return null;
}
Example 19
Project: bixie-master  File: MainClassTest.java View source code
@Test
public void test() {
    final File source_file = new File(testRoot + "ic_java/true_positives/TruePositives02.java");
    File classFileDir = null;
    try {
        classFileDir = compileJavaFile(source_file);
        Bixie.main(new String[] { "-j", classFileDir.getAbsolutePath(), "-logProver", "test" });
    } catch (IOException e) {
        e.printStackTrace();
        fail("Not yet implemented");
    } finally {
        if (classFileDir != null) {
            try {
                delete(classFileDir);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
Example 20
Project: android-platform-tools-base-master  File: Lib1.java View source code
public static String getContent() {
    InputStream input = Lib1.class.getResourceAsStream("Lib1.txt");
    if (input == null) {
        return "FAILED TO FIND Lib1.txt";
    }
    BufferedReader reader = null;
    try {
        reader = new BufferedReader(new InputStreamReader(input, "UTF-8"));
        return reader.readLine();
    } catch (IOException e) {
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (IOException e) {
            }
        }
    }
    return "FAILED TO READ CONTENT";
}
Example 21
Project: FTL-Hyperion-master  File: InputStreamSender.java View source code
protected final Object next() {
    try {
        int total = 0;
        while (total < chunk.length) {
            int count = input.read(chunk, total, chunk.length - total);
            if (count < 0) {
                if (total == 0)
                    return null;
                byte[] partial = new byte[total];
                System.arraycopy(chunk, 0, partial, 0, total);
                return partial;
            }
            total += count;
        }
    } catch (IOException ex) {
        throw new KryoNetException(ex);
    }
    return next(chunk);
}
Example 22
Project: geotools-old-master  File: TypeNameChooser.java View source code
public static String showTypeNameChooser(DataStore dataStore) {
    if (dataStore == null) {
        // could not connect
        return null;
    }
    String typeNames[];
    try {
        typeNames = dataStore.getTypeNames();
    } catch (IOException e) {
        return null;
    }
    if (typeNames.length == 0) {
        // could not connect
        return null;
    }
    if (typeNames.length == 1) {
        // no need to choose only one option
        return typeNames[0];
    } else {
        String typeName = (String) JOptionPane.showInputDialog(null, "Please select a type name.", "Type Name", JOptionPane.QUESTION_MESSAGE, null, typeNames, typeNames[0]);
        return typeName;
    }
}
Example 23
Project: hdt-java-master  File: HDTGenerateIndex.java View source code
public static void main(String[] args) {
    try {
        if (args.length != 1) {
            System.out.println("HDTGenerateIndex <hdtFile>");
            System.exit(-1);
        }
        String hdtFileName = args[0];
        HDT hdt = HDTManager.mapHDT(hdtFileName, null);
        if (hdtFileName.endsWith(".gz")) {
            hdtFileName = hdtFileName.substring(0, hdtFileName.length() - 3);
        }
        System.out.println("Generating " + hdtFileName + ".index");
        HDTManager.indexedHDT(hdt, new ProgressListener() {

            @Override
            public void notifyProgress(float level, String message) {
            //					System.out.println(message + "\t"+ Float.toString(level));
            }
        }).close();
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(-1);
    }
    ;
}
Example 24
Project: FallUML2013-master  File: Test.java View source code
public static void main(String[] args) throws Exception {
    //Change the path as per thr file location
    final String firstDiagram = "F:\\NEU_Files\\CSYE 7945_Software Engineering Project - Spring 2013\\ClubUML\\trunk\\Compare\\Test1.ecore";
    final String secondDiagram = "F:\\NEU_Files\\CSYE 7945_Software Engineering Project - Spring 2013\\ClubUML\\trunk\\Compare\\Test2.ecore";
    final String reportPath = "F:\\NEU_Files\\CSYE 7945_Software Engineering Project - Spring 2013\\report\\";
    try {
        CompareDiagrams compareDigs = new CompareDiagrams(firstDiagram, secondDiagram, reportPath);
        String reportFile = compareDigs.process();
        System.out.println("Report is saved to : " + reportFile);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Example 25
Project: checkstyle-master  File: InputFinalInTryWithResource.java View source code
public static void test() {
    try {
    } catch (RuntimeException e) {
    }
    try (@NotNull BufferedReader br = new BufferedReader(new InputStreamReader(null, "utf-8"))) {
    } catch (IOException e) {
    }
    try (final BufferedReader br = new BufferedReader(new InputStreamReader(null, "utf-8"))) {
    } catch (IOException e) {
    }
    try (final BufferedReader br = new BufferedReader(new InputStreamReader(null, "utf-8"));
        final BufferedReader br2 = new BufferedReader(new InputStreamReader(null, "utf-8"))) {
    } catch (IOException e) {
    }
}