Android Open Source - material-notes S Q L File Parser






From Project

Back to project page material-notes.

License

The source code is released under:

Apache License

If you think the Android project material-notes listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.materialnotes.data.source.sqlite;
//w  ww . j av  a 2  s . c om
import android.util.Log;

import com.materialnotes.util.Strings;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.regex.Pattern;

/**
 * Clase para parsear archivos *.sql
 *
 * @author Daniel Pedraza Arcega
 */
class SQLFileParser {

    private static final String TAG = SQLFileParser.class.getSimpleName();
    private static final Pattern COMMENT_PATTERN = Pattern.compile("(?:/\\*[^;]*?\\*/)|(?:--[^;]*?$)", Pattern.DOTALL | Pattern.MULTILINE);

    /**
     * Regresa todas las sentencias SQL contenidas en un archivo *.sql
     *
     * @param stream el stream del archivo *.sql
     * @return las sentencias SQL.
     */
    static String[] getSQLStatements(InputStream stream) {
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new InputStreamReader(stream));
            int r;
            StringBuilder sb = new StringBuilder();
            while ((r = reader.read()) != -1) sb.append((char) r);
            return COMMENT_PATTERN.matcher(sb).replaceAll(Strings.EMPTY).split(";");
        } catch (IOException ex) {
            Log.e(TAG, "Unable to parse SQL Statements", ex);
            return null;
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException ex) {
                    Log.e(TAG, "Unable to close stream", ex);
                }
            }
        }
    }
}




Java Source Code List

com.materialnotes.activity.EditNoteActivity.java
com.materialnotes.activity.MainActivity.java
com.materialnotes.activity.ViewNoteActivity.java
com.materialnotes.config.ConfigModule.java
com.materialnotes.data.Note.java
com.materialnotes.data.dao.NoteDAO.java
com.materialnotes.data.dao.impl.sqlite.NoteSQLiteDAO.java
com.materialnotes.data.source.sqlite.NotesDatabaseHelper.java
com.materialnotes.data.source.sqlite.SQLFileParser.java
com.materialnotes.util.Strings.java
com.materialnotes.view.ShowHideOnScroll.java
com.materialnotes.widget.AboutNoticeDialog.java
com.materialnotes.widget.NotesAdapter.java