Code example for XmlSerializer

Methods: attributesetOutputstartDocumentstartTag

0
    public void startTest(Test test) {
        try { 
            if (test instanceof TestCase) {
                TestCase testCase = (TestCase) test;
                checkForNewSuite(testCase);
                mSerializer.startTag("", TAG_CASE);
                mSerializer.attribute("", ATTRIBUTE_CLASS, mCurrentSuite);
                mSerializer.attribute("", ATTRIBUTE_NAME, testCase.getName());
 
                mTimeAlreadyWritten = false;
                mTestStartTime = System.currentTimeMillis();
            } 
        } catch (IOException e) {
            Log.e(LOG_TAG, safeMessage(e));
        } 
    } 
 
    private void checkForNewSuite(TestCase testCase) throws IOException {
        String suiteName = testCase.getClass().getName();
        if (mCurrentSuite == null || !mCurrentSuite.equals(suiteName)) {
            if (mCurrentSuite != null) {
                if (mMultiFile) {
                    close(); 
                } else { 
                    mSerializer.endTag("", TAG_SUITE);
                } 
            } 
 
            openIfRequired(suiteName);
 
            mSerializer.startTag("", TAG_SUITE);
            mSerializer.attribute("", ATTRIBUTE_NAME, suiteName);
            mCurrentSuite = suiteName;
        } 
    } 
 
    private void openIfRequired(String suiteName) throws IOException {
        if (mSerializer == null) {
            String fileName = mReportFile;
            if (mMultiFile) {
                fileName = fileName.replace("$(suite)", suiteName);
            } 
 
            if (mReportDir == null) {
                if (mContext.getFilesDir() != null) {
                    mOutputStream = mContext.openFileOutput(fileName, 0);
                } else { 
                    mOutputStream = mTargetContext.openFileOutput(fileName, 0);
                } 
            } else { 
                mOutputStream = new FileOutputStream(new File(mReportDir, fileName));
            } 
 
            mSerializer = Xml.newSerializer();
            mSerializer.setOutput(mOutputStream, ENCODING_UTF_8);
            mSerializer.startDocument(ENCODING_UTF_8, true);
            if (!mMultiFile) {
                mSerializer.startTag("", TAG_SUITES);
            } 
        } 
    } 
 
    @Override 
Contextual code suggestions in your IDE  Get Codota for Java