Example usage for java.lang SecurityException printStackTrace

List of usage examples for java.lang SecurityException printStackTrace

Introduction

In this page you can find the example usage for java.lang SecurityException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:it.drwolf.ridire.index.cwb.CWBCollocatesExtractor.java

public String extractCollocates(boolean calculateSize) {
    try {/*from   ww  w.  j av  a2s  .com*/
        this.dropDB();
        if (!this.userTx.isActive()) {
            this.userTx.begin();
        }
        this.entityManager.joinTransaction();
        String createDBQuery = "CREATE TABLE `" + CWBCollocatesExtractor.COLLOCATE_DB_PREFIX
                + this.conversationId
                + "` (`text_id` varchar(40) DEFAULT NULL,`beginPosition` int(11) DEFAULT NULL,`endPosition` int(11) DEFAULT NULL,`refnumber` bigint(20) NOT NULL,`dist` smallint(6) NOT NULL,`word` varchar(40) NOT NULL ";
        if (this.isIncludeLemmas()) {
            createDBQuery += ", `lemma` varchar(40) NOT NULL ";
        }
        if (this.isIncludePos()) {
            createDBQuery += ", `pos` varchar(40) NOT NULL ";
        }
        createDBQuery += ") ENGINE=MyISAM DEFAULT CHARSET=utf8";
        this.entityManager.createNativeQuery(createDBQuery).executeUpdate();
        this.entityManager.flush();
        this.entityManager.clear();
        this.userTx.commit();
        File tmpTabulate = this.tabulate();
        if (!this.userTx.isActive()) {
            this.userTx.begin();
        }
        this.entityManager.joinTransaction();
        this.entityManager.createNativeQuery("LOAD DATA LOCAL INFILE '" + tmpTabulate.getAbsolutePath()
                + "' INTO TABLE " + CWBCollocatesExtractor.COLLOCATE_DB_PREFIX + this.conversationId)
                .executeUpdate();
        if (calculateSize) {
            if (this.getCollocationBasedOn().equals(CWBCollocatesExtractor.BASED_ON_LEMMA)) {
                this.resultsSize = ((Number) this.entityManager
                        .createNativeQuery("select count(distinct(lemma)) from "
                                + CWBCollocatesExtractor.COLLOCATE_DB_PREFIX + this.conversationId)
                        .getSingleResult()).intValue();
            } else if (this.getCollocationBasedOn().equals(CWBCollocatesExtractor.BASED_ON_POS)) {
                this.resultsSize = ((Number) this.entityManager
                        .createNativeQuery("select count(distinct(pos)) from "
                                + CWBCollocatesExtractor.COLLOCATE_DB_PREFIX + this.conversationId)
                        .getSingleResult()).intValue();
            } else {
                this.resultsSize = ((Number) this.entityManager
                        .createNativeQuery("select count(distinct(word)) from "
                                + CWBCollocatesExtractor.COLLOCATE_DB_PREFIX + this.conversationId)
                        .getSingleResult()).intValue();
            }
        }
        long r1 = ((Number) this.entityManager.createNativeQuery(
                "select count(*) from " + CWBCollocatesExtractor.COLLOCATE_DB_PREFIX + this.conversationId
                        + " where dist between -" + this.getDistanceLeft() + " and " + this.getDistanceRight())
                .getSingleResult()).longValue();
        this.entityManager.flush();
        this.entityManager.clear();
        this.userTx.commit();
        String collBasedOn = "word";
        String freqTable = "freq_";
        if (this.getCollocationBasedOn().equals(CWBCollocatesExtractor.BASED_ON_LEMMA)) {
            collBasedOn = "lemma";
            freqTable += "lemma_";
        } else if (this.getCollocationBasedOn().equals(CWBCollocatesExtractor.BASED_ON_POS)) {
            collBasedOn = "pos";
            freqTable += "easypos_";
        } else {
            freqTable += "forma_";
        }
        if (this.getFunctionalMetadatum() >= 0) {
            FunctionalMetadatum fm = this.entityManager.find(FunctionalMetadatum.class,
                    this.getFunctionalMetadatum());
            freqTable += fm.getDescription().trim().replaceAll("\\s", "_");
        } else if (this.getSemanticMetadatum() >= 0) {
            SemanticMetadatum sm = this.entityManager.find(SemanticMetadatum.class,
                    this.getSemanticMetadatum());
            freqTable += sm.getDescription().trim().replaceAll("\\s", "_");
        } else {
            freqTable += "all";
        }
        long n = this.corpusSizeParams.getCorpusSize(freqTable.substring(5)).longValue();
        String nativeQuery = "select %1$s.%2$s, count(%1$s.%2$s) as observed,(" + r1 + " * (%3$s.freq) / " + n
                + ") as expected,";
        String significance = " sign(COUNT(%1$s.%2$s) - (" + r1 + " * (%3$s.freq) / " + n
                + ")) * 2 * ( IF(COUNT(%1$s.%2$s) > 0, COUNT(%1$s.%2$s) * log(COUNT(%1$s.%2$s) / (" + r1
                + " * (%3$s.freq) / " + n + ")), 0) + IF((" + r1 + " - COUNT(%1$s.%2$s)) > 0, (" + r1
                + " - COUNT(%1$s.%2$s)) * log((" + r1 + " - COUNT(%1$s.%2$s)) / (" + r1 + " * (" + n
                + " - (%3$s.freq)) / " + n + ")), 0) + IF((CAST(%3$s.freq AS SIGNED) - COUNT(%1$s.%2$s)) > 0, "
                + "(CAST(%3$s.freq AS SIGNED) - COUNT(%1$s.%2$s)) * log((CAST(%3$s.freq AS SIGNED) - COUNT(%1$s.%2$s)) / ("
                + (n - r1) + " * (%3$s.freq) / " + n + ")), 0) + " + "IF((" + (n - r1)
                + " - (CAST(%3$s.freq AS SIGNED) - COUNT(%1$s.%2$s))) > 0, (" + (n - r1)
                + " - (CAST(%3$s.freq AS SIGNED) - COUNT(%1$s.%2$s))) * log((" + (n - r1)
                + " - (CAST(%3$s.freq AS SIGNED) - COUNT(%1$s.%2$s))) / (" + (n - r1) + " * (" + n
                + " - (%3$s.freq)) / " + n + ")), 0) ) as significance, ";
        if (this.getScore().equals(CWBCollocatesExtractor.MI_SCORE)) {
            significance = "log2(COUNT(%1$s.%2$s)/(" + r1 + " * (%3$s.freq) / " + n + ")) as significance, ";
        } else if (this.getScore().equals(CWBCollocatesExtractor.T_SCORE)) {
            significance = "(COUNT(%1$s.%2$s) - (" + r1 + " * (%3$s.freq) / " + n
                    + "))/sqrt(COUNT(%1$s.%2$s)) as significance, ";
        } else if (this.getScore().equals(CWBCollocatesExtractor.LOGDICE_SCORE)) {
            String subquery = "SELECT COUNT(DISTINCT refnumber) from %1$s WHERE dist between -"
                    + this.getDistanceLeft() + " and " + this.getDistanceRight();
            if (!this.userTx.isActive()) {
                this.userTx.begin();
            }
            subquery = String.format(subquery,
                    CWBCollocatesExtractor.COLLOCATE_DB_PREFIX + this.conversationId);
            this.entityManager.joinTransaction();
            Number diceNodeF = (Number) this.entityManager.createNativeQuery(subquery).getSingleResult();
            this.entityManager.flush();
            this.entityManager.clear();
            this.userTx.commit();
            String pCollNodeE = "(COUNT(DISTINCT refnumber) / " + diceNodeF.longValue() + ")";
            String pNodeColl = "(COUNT(%1$s.%2$s) / (%3$s.freq))";
            significance = "2 / ((1 / " + pCollNodeE + ") + (1 / " + pNodeColl + ")) as significance, ";

        }
        nativeQuery += significance;
        nativeQuery += " %3$s.freq, " + "count(distinct(text_id)) as text_id_count "
                + "from %1$s, %3$s where %1$s.%2$s = %3$s.item ";
        if (this.isIncludePos() && this.getFilterOnPoS() != null && this.getFilterOnPoS().length() > 0
                && !this.getFilterOnPoS().equals("Tutti")) {
            nativeQuery += " and %1$s.pos='" + this.getFilterOnPoS().trim() + "'";
        }
        nativeQuery += " and dist between -" + this.getDistanceLeft() + " and " + this.getDistanceRight()
                + " and %3$s.freq >= " + this.getFreqMinColl() + " group by %1$s.%2$s having observed >= "
                + this.getFreqMinNC() + " order by significance desc LIMIT " + this.getFirstResult() + ", "
                + this.getPageSize();

        nativeQuery = String.format(nativeQuery,
                CWBCollocatesExtractor.COLLOCATE_DB_PREFIX + this.conversationId, collBasedOn, freqTable);
        System.out.println(nativeQuery);
        if (!this.userTx.isActive()) {
            this.userTx.begin();
        }
        this.entityManager.joinTransaction();
        List<Object[]> res = this.entityManager.createNativeQuery(nativeQuery).getResultList();
        this.entityManager.flush();
        this.entityManager.clear();
        this.userTx.commit();
        this.cwbCollocateResults = new ArrayList<CWBCollocateResult>();
        for (Object[] r : res) {
            CWBCollocateResult cwbCollocateResult = new CWBCollocateResult(r[0] + "",
                    ((Number) r[4]).longValue(), ((Number) r[2]).doubleValue(), ((Number) r[1]).longValue(),
                    ((Number) r[5]).longValue(), ((Number) r[3]).doubleValue(), this.getScore());
            this.cwbCollocateResults.add(cwbCollocateResult);
        }
    } catch (SecurityException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SystemException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (NotSupportedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (RollbackException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (HeuristicMixedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (HeuristicRollbackException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return "OK";
}

From source file:com.danvelazco.fbwrapper.activity.BaseFacebookWebViewActivity.java

/**
 * Check whether this device has internet connection or not.
 *
 * @return {@link boolean}// w  w  w . ja v a2 s .com
 */
private boolean checkNetworkConnection() {
    try {
        NetworkInfo networkInfo = mConnectivityManager.getActiveNetworkInfo();
        if (networkInfo != null) {
            return networkInfo.isConnected();
        }
        return false;
    } catch (SecurityException e) {
        // Catch the Security Exception in case the user revokes the ACCESS_NETWORK_STATE permission
        e.printStackTrace();
        // Let's assume the device has internet access
        return true;
    }
}

From source file:com.processpuzzle.fundamental_types.uniqueidentifier.domain.PrefixedIncNumberedIdFactory.java

@SuppressWarnings("unchecked")
private UniqueIdentifier generateUniqueIdentifierByType(String idType, String identifier) {
    UniqueIdentifier uniqueIdentifier = null;
    if (idType != null && !idType.equals("")) {
        Class identifierClass = null;
        try {// w  ww. j a v a  2s.co  m
            identifierClass = Class.forName(idType);
            try {
                Class[] argumentClasses = new Class[] { String.class };
                Object[] arguments = new Object[] { identifier };
                Constructor identifierConstructor = identifierClass.getConstructor(argumentClasses);
                uniqueIdentifier = (UniqueIdentifier) identifierConstructor.newInstance(arguments);
            } catch (SecurityException e) {
                throw new UniqueIdentifierInstantiationException(identifierClass.getName(), identifier);
            } catch (NoSuchMethodException e) {
                throw new UniqueIdentifierInstantiationException(identifierClass.getName(), identifier);
            } catch (IllegalArgumentException e) {
                throw new UniqueIdentifierInstantiationException(identifierClass.getName(), identifier);
            } catch (InvocationTargetException e) {
                throw new UniqueIdentifierInstantiationException(identifierClass.getName(), identifier);
            }

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }

    return uniqueIdentifier;

}

From source file:org.energy_home.jemma.osgi.ah.hap.client.HapCoreService.java

public void _hap(CommandInterpreter ci) {
    String command = ci.nextArgument();
    Method method = null;//ww  w.ja  va  2 s  . co m

    try {
        method = this.getClass().getMethod("_" + command, new Class[] { CommandInterpreter.class });
    } catch (SecurityException e) {
        ci.println("Invalid hap command");
        return;
    } catch (NoSuchMethodException e) {
        ci.println("Invalid hap command");
        return;
    }

    try {
        method.invoke(this, new Object[] { ci });
    } catch (Exception e) {
        e.printStackTrace();
        return;
    }
}

From source file:com.israel_fl.smartadaptweather.activities.MainActivity.java

@Override
public void onConnected(@Nullable Bundle bundle) {
    Log.d(TAG, "onConnected called");

    try {//  w ww  . j ava 2s .c  om
        mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
    } catch (SecurityException e) {
        e.printStackTrace();
    }

    Log.d(TAG, "Last Location: " + mLastLocation);

    latitude = mLastLocation.getLatitude();
    longitude = mLastLocation.getLongitude();
    Log.d(TAG, "Latitude: " + latitude + " Longitude: " + longitude);

    // Set title bar name to name of city
    Geocoder gcd = new Geocoder(getApplicationContext(), Locale.getDefault());
    try {
        List<Address> addresses = gcd.getFromLocation(latitude, longitude, 1);
        if (addresses.size() > 0) {
            cityName = addresses.get(0).getLocality();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    // Set title to city name
    if (getSupportActionBar() != null) {
        getSupportActionBar().setTitle(cityName);
    }

    getWeatherInfo(); // begin weather api
    modifyConfig(); // modify weather settings

    Log.d(TAG, "Last Location: " + mLastLocation);

}

From source file:com.connectsdk.discovery.DiscoveryManager.java

/**
 * Unregisters a DeviceService with DiscoveryManager. If no other DeviceServices are set to being discovered with the associated DiscoveryProvider, then that DiscoveryProvider instance will be stopped and shut down.
 *
 * @param deviceClass Class for DeviceService that should no longer be discovered
 * @param discoveryClass Class for DiscoveryProvider that is discovering DeviceServices of deviceClass type
 *//*from  w  w  w .j  ava  2s  .  co  m*/
public void unregisterDeviceService(Class<?> deviceClass, Class<?> discoveryClass) {
    if (!deviceClass.isAssignableFrom(DeviceService.class)) {
        return;
    }

    if (!discoveryClass.isAssignableFrom(DiscoveryProvider.class)) {
        return;
    }

    try {
        DiscoveryProvider discoveryProvider = null;

        for (DiscoveryProvider dp : discoveryProviders) {
            if (dp.getClass().isAssignableFrom(discoveryClass)) {
                discoveryProvider = dp;
                break;
            }
        }

        if (discoveryProvider == null)
            return;

        Method m = deviceClass.getMethod("discoveryParameters");
        Object result = m.invoke(null);
        JSONObject discoveryParameters = (JSONObject) result;
        String serviceFilter = (String) discoveryParameters.get("serviceId");

        deviceClasses.remove(serviceFilter);

        discoveryProvider.removeDeviceFilter(discoveryParameters);

        if (discoveryProvider.isEmpty()) {
            discoveryProvider.stop();
            discoveryProviders.remove(discoveryProvider);
        }
    } catch (SecurityException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:com.connectsdk.discovery.DiscoveryManager.java

/**
 * Registers a DeviceService with DiscoveryManager and tells it which DiscoveryProvider to use to find it. Each DeviceService has a JSONObject of discovery parameters that its DiscoveryProvider will use to find it.
 *
 * @param deviceClass Class for object that should be instantiated when DeviceService is found
 * @param discoveryClass Class for object that should discover this DeviceService. If a DiscoveryProvider of this class already exists, then the existing DiscoveryProvider will be used.
 *//*from   ww w .  j  a v a 2 s  .  co m*/
public void registerDeviceService(Class<? extends DeviceService> deviceClass,
        Class<? extends DiscoveryProvider> discoveryClass) {
    if (!DeviceService.class.isAssignableFrom(deviceClass))
        return;

    if (!DiscoveryProvider.class.isAssignableFrom(discoveryClass))
        return;

    try {
        DiscoveryProvider discoveryProvider = null;

        for (DiscoveryProvider dp : discoveryProviders) {
            if (dp.getClass().isAssignableFrom(discoveryClass)) {
                discoveryProvider = dp;
                break;
            }
        }

        if (discoveryProvider == null) {
            Constructor<? extends DiscoveryProvider> myConstructor = discoveryClass
                    .getConstructor(Context.class);
            Object myObj = myConstructor.newInstance(new Object[] { context });
            discoveryProvider = (DiscoveryProvider) myObj;

            discoveryProvider.addListener(this);
            discoveryProviders.add(discoveryProvider);
        }
        Method m = deviceClass.getMethod("discoveryParameters");
        Object result = m.invoke(null);
        JSONObject discoveryParameters = (JSONObject) result;
        String serviceFilter = (String) discoveryParameters.get("serviceId");

        deviceClasses.put(serviceFilter, deviceClass);

        discoveryProvider.addDeviceFilter(discoveryParameters);
    } catch (SecurityException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:org.saydroid.tether.usb.Engine.java

public boolean startupCheck() {
    boolean startupCheckSuccess = false;

    boolean mSupportedKernel = false;

    this.checkDirs();

    if (!this.hasRootPermission()) {
        mSupportedKernel = false;//from  w w w  .  j  a  v  a  2s  .c  o  m
    }

    if (this.binariesExists() == false) {
        if (this.hasRootPermission()) {
            this.installFiles();
        }
    }

    /*
    * Add a function for get setting from settings.db to see if there is tether_supported
    * need to write a function to dump the settings.db secure table into a file and
    * read from this file to see if contains tether_supported. This function is defined
    * inside CoreTask.java
    */
    boolean dumpSettingSuccess = false;
    boolean setGlobalSettingFail = false;
    if (this.hasRootPermission()) {
        if ((this.dumpGlobalSettings() == false) || (this.dumpGlobalSettingsMaxID() == false)) {
            //this.openFailToDumpSecureSettingDialog();
            dumpSettingSuccess = false;
        } else
            dumpSettingSuccess = true;
    }
    int iMaxId = -1;
    if (!this.checkGlobalSetting(this.mGlobalSetting_tether_supported)) {
        iMaxId = this.globalSettingMaxId();
        if (iMaxId < 0) { //error occurs during retrieve maxId of secure table, return -1 if error
            Log.d(TAG, "cannot read system setting's max id during checking tether_supported...");
        } else { //if there is no error to retrieve maxId, then insert with new name field and maxid
            iMaxId = iMaxId + 1;
            if (!this.globalSettingInsertAndEnable(this.mGlobalSetting_tether_supported, iMaxId, 1)) {
                setGlobalSettingFail = true;
                Log.d(TAG, "cannot insert and enable " + this.mGlobalSetting_tether_supported);
            }
        }
    } else if (!this.globalSettingIsEnabled(this.mGlobalSetting_tether_supported, 1)) {
        if (!this.globalSettingEnable(this.mGlobalSetting_tether_supported, 1)) {
            setGlobalSettingFail = true;
            Log.d(TAG, "cannot enable " + this.mGlobalSetting_tether_supported);
        }
    } else {
        Log.d(TAG, this.mGlobalSetting_tether_supported + " has been enabled already");
    }

    if (!this.checkGlobalSetting(this.mGlobalSetting_tether_dun_required)) {
        iMaxId = this.globalSettingMaxId();
        if (iMaxId < 0) { //error occurs during retrieve maxId of secure table, return -1 if error
            Log.d(TAG, "cannot read system setting's max id during checking tether_dun_required...");
        } else { //if there is no error to retrieve maxId, then insert with new name field and maxid
            iMaxId = iMaxId + 1;
            if (!this.globalSettingInsertAndEnable(this.mGlobalSetting_tether_dun_required, iMaxId, 0)) {
                setGlobalSettingFail = true;
                Log.d(TAG, "cannot insert and enable " + this.mGlobalSetting_tether_dun_required);
            }
        }
    } else if (!this.globalSettingIsEnabled(this.mGlobalSetting_tether_dun_required, 0)) {
        if (!this.globalSettingEnable(this.mGlobalSetting_tether_dun_required, 0)) {
            setGlobalSettingFail = true;
            Log.d(TAG, "cannot enable " + this.mGlobalSetting_tether_dun_required);
        }
    } else {
        Log.d(TAG, this.mGlobalSetting_tether_dun_required + " has been enabled already");
    }

    Log.d(TAG, "dumpSettingSuccess is:" + dumpSettingSuccess);
    Log.d(TAG, "setSecureSettingFail is:" + setGlobalSettingFail);
    if (dumpSettingSuccess && !setGlobalSettingFail) {

        //Use reflection to retrieve the isTetheringSupported method from connnectivityManager
        ConnectivityManager cm = SgsApplication.getConnectivityManager();
        Method isTetheringSupportedLocal = null;
        Method getTetherableUsbRegexsLocal = null; //added temp
        String[] tetherRegex;
        try {
            isTetheringSupportedLocal = cm.getClass().getMethod("isTetheringSupported");
            getTetherableUsbRegexsLocal = cm.getClass().getMethod("getTetherableUsbRegexs");
        } catch (SecurityException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        //Use this high level general method to make judgment
        try {
            mSupportedKernel = (Boolean) isTetheringSupportedLocal.invoke(cm);
            tetherRegex = (String[]) getTetherableUsbRegexsLocal.invoke(cm);
            Log.d(TAG, "supportedKernel value is:" + mSupportedKernel);

            //note: cannot use (boolean) isTetheringSupportedLocal.invoke(cm);
        } catch (IllegalArgumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        if (!mSupportedKernel) {
            //this.openUnsupportedKernelDialog();
        }
    }

    //TODO: those lines below for debug only
    int tetherEnabledInSettings = 0;
    try {
        tetherEnabledInSettings = Settings.Global.getInt(SgsApplication.getInstance().getContentResolver(),
                "tether_supported");
    } catch (Settings.SettingNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    Log.d(TAG, "tetherEnabledInSettings is ..." + tetherEnabledInSettings);

    //SgsApplication.getInstance().checkForUpdate();

    //this.toggleStartStop();

    startupCheckSuccess = true;
    getConfigurationService().putBoolean(SgsConfigurationEntry.GENERAL_STARTUP_CHECK, !startupCheckSuccess);
    getConfigurationService().commit();

    return startupCheckSuccess;
}

From source file:org.elasticsearch.index.mapper.attachment.AttachmentMapper.java

@Override
public void parse(ParseContext context) throws IOException {
    System.out.println("Parse Index Request");
    //      byte[] content = null;
    String contentType = null;//from w  w w  .j a va2s .  c o m
    int indexedChars = defaultIndexedChars;
    String name = null;

    Map fieldMapping = new HashMap<String, Object>();

    XContentParser parser = context.parser();
    //create reference //TODO

    Map<String, Object> parseAndChecksumResults = null;
    XContentParser.Token token = parser.currentToken();
    try {
        if (token == XContentParser.Token.VALUE_STRING || token == XContentParser.Token.VALUE_EMBEDDED_OBJECT) {
            parseAndChecksumResults = parseAndCalculateChecksumWithThreads(parser, indexedChars);
        } else {
            String currentFieldName = null;
            while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
                if (token == XContentParser.Token.FIELD_NAME) {
                    currentFieldName = parser.currentName();
                    System.out.println(currentFieldName);
                } else {
                    if ("content".equals(currentFieldName)) {
                        //for both smile and string
                        parseAndChecksumResults = parseAndCalculateChecksumWithThreads(parser, indexedChars);

                    } else if (isString(token) && "_content_type".equals(currentFieldName)) {
                        contentType = parser.text();
                    } else if (isString(token) && "_name".equals(currentFieldName)) {
                        name = parser.text();
                    } else if (token == XContentParser.Token.VALUE_NUMBER
                            && ("_indexed_chars".equals(currentFieldName)
                                    || "_indexedChars".equals(currentFieldName))) {
                        indexedChars = parser.intValue();
                    } else {
                        logger.info("non-default mapping:" + currentFieldName);
                        if ("content".equals(currentFieldName)) {
                        } else {
                            Object object = parser.objectText();
                            System.out.println(object);
                            // content = parser.binaryValue();
                            fieldMapping.put(currentFieldName, object);
                        }
                    }
                }
                // Handle the mapping when doc come

                logger.info("fieldMapping" + fieldMapping);
            }
        }
    } catch (SecurityException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (NoSuchFieldException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();

    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ExecutionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (TimeoutException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    if (parseAndChecksumResults == null) {
        throw new IOException("parse failed, result is null");
    }
    CalcualteChecksumResult checksumResult = (CalcualteChecksumResult) parseAndChecksumResults
            .get("checksumResult");
    ParseResult parseResult = (ParseResult) parseAndChecksumResults.get("parseResult");

    Metadata metadata = parseResult.metadata;
    if (contentType != null) {
        metadata.add(Metadata.CONTENT_TYPE, contentType);
    }
    if (name != null) {
        metadata.add(Metadata.RESOURCE_NAME_KEY, name);
    }

    // used same interface for image / non-image as decouple detection
    // logic to detect done by tika on the fly. but check aftewards
    // logger.info("parsedContent" + parsedContent);

    if (isImage(metadata)) {
        System.out.println(metadata);
    } else {
        if (parseResult.parseContent.equalsIgnoreCase("")) {
            logger.info("Content is empty after parsed by Tika");
            System.out.println(metadata);
            try {
                throw new TikaException("Content is empty after parsed by Tika");
            } catch (TikaException e) {
                // TODO Auto-generated catch block
                throw new IOException(e);
            }
        }
    }

    context.externalValue(parseResult.parseContent);
    contentMapper.parse(context);

    context.externalValue(name);
    nameMapper.parse(context);

    context.externalValue(metadata.get(Metadata.DATE));
    dateMapper.parse(context);

    context.externalValue(metadata.get(Metadata.TITLE));
    titleMapper.parse(context);

    context.externalValue(metadata.get(Metadata.AUTHOR));
    authorMapper.parse(context);

    context.externalValue("ImKeyWord");
    keywordsMapper.parse(context);

    context.externalValue(metadata.get(Metadata.CONTENT_TYPE));
    contentTypeMapper.parse(context);

    context.externalValue(metadata);
    imageExifTikaMetaMapper.parse(context);

    FileMeta fileMeta = new FileMeta();
    fileMeta.setChecksum(checksumResult.checksum);
    fileMeta.setChecksumTook(checksumResult.took);
    fileMeta.setParseTook(parseResult.took);

    context.externalValue(fileMeta);
    fileMetaMapper.parse(context);

}

From source file:arc.noaa.weather.activities.MainActivity.java

@Override
protected void onDestroy() {
    super.onDestroy();
    destroyed = true;/*from  w w w . j a v  a2s.  com*/

    if (locationManager != null) {
        try {
            locationManager.removeUpdates(MainActivity.this);
        } catch (SecurityException e) {
            e.printStackTrace();
        }
    }
}