Search in sources :

Example 96 with String

use of java.lang.String in project jdk8u_jdk by JetBrains.

the class Assembler method GenJCov.

/*
 * generate file of coverage data
 */
// for JCovd.readLine() calls
@SuppressWarnings("deprecation")
public void GenJCov(Environment env) {
    try {
        File outFile = env.getcovFile();
        if (outFile.exists()) {
            DataInputStream JCovd = new DataInputStream(new BufferedInputStream(new FileInputStream(outFile)));
            String CurrLine = null;
            boolean first = true;
            String Class;
            CurrLine = JCovd.readLine();
            if ((CurrLine != null) && CurrLine.startsWith(JcovMagicLine)) {
                while ((CurrLine = JCovd.readLine()) != null) {
                    if (CurrLine.startsWith(JcovClassLine)) {
                        first = true;
                        for (Enumeration<String> e = SourceClassList.elements(); e.hasMoreElements(); ) {
                            String clsName = CurrLine.substring(JcovClassLine.length());
                            int idx = clsName.indexOf(' ');
                            if (idx != -1) {
                                clsName = clsName.substring(0, idx);
                            }
                            Class = e.nextElement();
                            if (Class.compareTo(clsName) == 0) {
                                first = false;
                                break;
                            }
                        }
                    }
                    if (// re-write old class
                    first)
                        TmpCovTable.addElement(CurrLine);
                }
            }
            JCovd.close();
        }
        PrintStream CovFile = new PrintStream(new DataOutputStream(new FileOutputStream(outFile)));
        CovFile.println(JcovMagicLine);
        for (Enumeration<String> e = TmpCovTable.elements(); e.hasMoreElements(); ) {
            CovFile.println(e.nextElement());
        }
        CovFile.close();
    } catch (FileNotFoundException e) {
        System.out.println("ERROR: " + e);
    } catch (IOException e) {
        System.out.println("ERROR: " + e);
    }
}
Also used : PrintStream(java.io.PrintStream) DataOutputStream(java.io.DataOutputStream) FileNotFoundException(java.io.FileNotFoundException) String(java.lang.String) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream) BufferedInputStream(java.io.BufferedInputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 97 with String

use of java.lang.String in project TaEmCasa by Dionen.

the class JsonRequestCharsetTest method specifiedCharsetJsonObject.

@Test
public void specifiedCharsetJsonObject() throws Exception {
    byte[] data = jsonObjectString().getBytes(Charset.forName("ISO-8859-1"));
    Map<String, String> headers = new HashMap<String, String>();
    headers.put("Content-Type", "application/json; charset=iso-8859-1");
    NetworkResponse network = new NetworkResponse(data, headers);
    JsonObjectRequest objectRequest = new JsonObjectRequest("", null, null, null);
    Response<JSONObject> objectResponse = objectRequest.parseNetworkResponse(network);
    assertNotNull(objectResponse);
    assertTrue(objectResponse.isSuccess());
    //don't check the text in Czech, ISO-8859-1 doesn't support some Czech characters
    assertEquals(COPY_VALUE, objectResponse.result.getString(COPY_NAME));
}
Also used : JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) NetworkResponse(com.android.volley.NetworkResponse) String(java.lang.String) JsonObjectRequest(com.android.volley.toolbox.JsonObjectRequest) Test(org.junit.Test)

Example 98 with String

use of java.lang.String in project TaEmCasa by Dionen.

the class JsonRequestCharsetTest method specifiedCharsetJsonArray.

@Test
public void specifiedCharsetJsonArray() throws Exception {
    byte[] data = jsonArrayString().getBytes(Charset.forName("ISO-8859-2"));
    Map<String, String> headers = new HashMap<String, String>();
    headers.put("Content-Type", "application/json; charset=iso-8859-2");
    NetworkResponse network = new NetworkResponse(data, headers);
    JsonArrayRequest arrayRequest = new JsonArrayRequest("", null, null);
    Response<JSONArray> arrayResponse = arrayRequest.parseNetworkResponse(network);
    assertNotNull(arrayResponse);
    assertTrue(arrayResponse.isSuccess());
    assertEquals(TEXT_VALUE, arrayResponse.result.getString(TEXT_INDEX));
// don't check the copyright symbol, ISO-8859-2 doesn't have it, but it has Czech characters
}
Also used : JsonArrayRequest(com.android.volley.toolbox.JsonArrayRequest) HashMap(java.util.HashMap) NetworkResponse(com.android.volley.NetworkResponse) JSONArray(org.json.JSONArray) String(java.lang.String) Test(org.junit.Test)

Example 99 with String

use of java.lang.String in project tomee by apache.

the class OpenejbJarTest method unmarshalAndMarshal.

private <T> void unmarshalAndMarshal(final Class<T> type, final java.lang.String xmlFileName, final java.lang.String expectedFile) throws Exception {
    final InputStream in = getInputStream(xmlFileName);
    assertNotNull(in);
    final Object object = JaxbOpenejbJar2.unmarshal(type, in);
    final String actual = JaxbOpenejbJar2.marshal(type, object);
    final String expected;
    if (xmlFileName.equals(expectedFile)) {
        expected = readContent(getInputStream(xmlFileName));
    } else {
        expected = readContent(getInputStream(expectedFile));
    }
    XMLUnit.setIgnoreWhitespace(true);
    try {
        final Diff myDiff = new DetailedDiff(new Diff(expected, actual));
        assertTrue("Files are not similar " + myDiff, myDiff.similar());
    } catch (final AssertionFailedError e) {
        e.printStackTrace();
        assertEquals(expected, actual);
        throw e;
    }
}
Also used : DetailedDiff(org.custommonkey.xmlunit.DetailedDiff) DetailedDiff(org.custommonkey.xmlunit.DetailedDiff) Diff(org.custommonkey.xmlunit.Diff) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) String(java.lang.String) AssertionFailedError(junit.framework.AssertionFailedError)

Example 100 with String

use of java.lang.String in project android_frameworks_base by crdroidandroid.

the class TextGraphReader method readKeyValueAssignments.

private KeyValueMap readKeyValueAssignments(PatternScanner scanner, Pattern endPattern) throws GraphIOException {
    // Our parser is a state-machine, and these are our states
    final int STATE_IDENTIFIER = 0;
    final int STATE_EQUALS = 1;
    final int STATE_VALUE = 2;
    final int STATE_POST_VALUE = 3;
    final Pattern equalsPattern = Pattern.compile("=");
    final Pattern semicolonPattern = Pattern.compile(";");
    final Pattern wordPattern = Pattern.compile("[a-zA-Z]+[a-zA-Z0-9]*");
    final Pattern stringPattern = Pattern.compile("'[^']*'|\\\"[^\\\"]*\\\"");
    final Pattern intPattern = Pattern.compile("[0-9]+");
    final Pattern floatPattern = Pattern.compile("[0-9]*\\.[0-9]+f?");
    final Pattern referencePattern = Pattern.compile("\\$[a-zA-Z]+[a-zA-Z0-9]");
    final Pattern booleanPattern = Pattern.compile("true|false");
    int state = STATE_IDENTIFIER;
    KeyValueMap newVals = new KeyValueMap();
    String curKey = null;
    String curValue = null;
    while (!scanner.atEnd() && !(endPattern != null && scanner.peek(endPattern))) {
        switch(state) {
            case STATE_IDENTIFIER:
                curKey = scanner.eat(wordPattern, "<identifier>");
                state = STATE_EQUALS;
                break;
            case STATE_EQUALS:
                scanner.eat(equalsPattern, "=");
                state = STATE_VALUE;
                break;
            case STATE_VALUE:
                if ((curValue = scanner.tryEat(stringPattern)) != null) {
                    newVals.put(curKey, curValue.substring(1, curValue.length() - 1));
                } else if ((curValue = scanner.tryEat(referencePattern)) != null) {
                    String refName = curValue.substring(1, curValue.length());
                    Object referencedObject = mBoundReferences != null ? mBoundReferences.get(refName) : null;
                    if (referencedObject == null) {
                        throw new GraphIOException("Unknown object reference to '" + refName + "'!");
                    }
                    newVals.put(curKey, referencedObject);
                } else if ((curValue = scanner.tryEat(booleanPattern)) != null) {
                    newVals.put(curKey, Boolean.parseBoolean(curValue));
                } else if ((curValue = scanner.tryEat(floatPattern)) != null) {
                    newVals.put(curKey, Float.parseFloat(curValue));
                } else if ((curValue = scanner.tryEat(intPattern)) != null) {
                    newVals.put(curKey, Integer.parseInt(curValue));
                } else {
                    throw new GraphIOException(scanner.unexpectedTokenMessage("<value>"));
                }
                state = STATE_POST_VALUE;
                break;
            case STATE_POST_VALUE:
                scanner.eat(semicolonPattern, ";");
                state = STATE_IDENTIFIER;
                break;
        }
    }
    // Make sure end is expected
    if (state != STATE_IDENTIFIER && state != STATE_POST_VALUE) {
        throw new GraphIOException("Unexpected end of assignments on line " + scanner.lineNo() + "!");
    }
    return newVals;
}
Also used : Pattern(java.util.regex.Pattern) KeyValueMap(android.filterfw.core.KeyValueMap) String(java.lang.String) GraphIOException(android.filterfw.io.GraphIOException)

Aggregations

String (java.lang.String)192 Override (java.lang.Override)35 Test (org.junit.Test)33 ArrayList (java.util.ArrayList)27 HashMap (java.util.HashMap)20 PreparedStatement (java.sql.PreparedStatement)16 ResultSet (java.sql.ResultSet)16 IOException (java.io.IOException)13 KeyValueMap (android.filterfw.core.KeyValueMap)12 GraphIOException (android.filterfw.io.GraphIOException)12 Statement (java.sql.Statement)12 Pattern (java.util.regex.Pattern)12 SQLException (java.sql.SQLException)11 Exception (java.lang.Exception)9 Map (java.util.Map)9 SQLTimeoutException (java.sql.SQLTimeoutException)8 List (java.util.List)8 Object (java.lang.Object)7 ParseException (java.text.ParseException)7 DbModel (net.tsz.afinal.db.sqlite.DbModel)7