Example usage for java.io PrintStream append

List of usage examples for java.io PrintStream append

Introduction

In this page you can find the example usage for java.io PrintStream append.

Prototype

public PrintStream append(char c) 

Source Link

Document

Appends the specified character to this output stream.

Usage

From source file:org.forgerock.openidm.shell.impl.BasicCommandScope.java

/**
 * Produce help text./*from  w w w .  j  a  v a2s.  c  om*/
 *
 * @param session the command session.
 */
@Descriptor("Displays available commands.")
public void help(CommandSession session) {
    ServiceLoader<CustomCommandScope> ldr = ServiceLoader.load(CustomCommandScope.class);
    PrintStream console = session.getConsole();

    for (CustomCommandScope cmdScope : ldr) {
        String scope = cmdScope.getScope();
        Map<String, String> functionMap = cmdScope.getFunctionMap();

        if (StringUtils.isNotEmpty(scope) && functionMap != null) {
            int maxEntryLen = 0;

            for (Map.Entry<String, String> entry : functionMap.entrySet()) {
                int len = scope.length() + entry.getKey().length() + 4; // 4 for ':' +3 space
                maxEntryLen = len > maxEntryLen ? len : maxEntryLen;
            }

            StringBuilder spaceBuilder = new StringBuilder();

            for (int i = 0; i < maxEntryLen; i++) {
                spaceBuilder.append(' ');
            }

            String spacer = spaceBuilder.toString();

            for (Map.Entry<String, String> entry : functionMap.entrySet()) {
                String name = scope + ":" + entry.getKey();
                String desc = entry.getValue();

                console.append(LEAD_OPTION_SPACE).append(name)
                        .append(spacer.substring(Math.min(name.length(), spacer.length()))).println(desc);
            }
        }
    }
}

From source file:com.vonglasow.michael.satstat.ui.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    defaultUEH = Thread.getDefaultUncaughtExceptionHandler();

    Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
        public void uncaughtException(Thread t, Throwable e) {
            Context c = getApplicationContext();
            File dumpDir = c.getExternalFilesDir(null);
            DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.ROOT);
            fmt.setTimeZone(TimeZone.getTimeZone("UTC"));
            String fileName = String.format("satstat-%s.log", fmt.format(new Date(System.currentTimeMillis())));

            File dumpFile = new File(dumpDir, fileName);
            PrintStream s;
            try {
                InputStream buildInStream = getResources().openRawResource(R.raw.build);
                s = new PrintStream(dumpFile);
                s.append("SatStat build: ");

                int i;
                try {
                    i = buildInStream.read();
                    while (i != -1) {
                        s.write(i);/*from   w  w  w . jav  a 2s . co m*/
                        i = buildInStream.read();
                    }
                    buildInStream.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }

                s.append("\n\n");
                e.printStackTrace(s);
                s.flush();
                s.close();

                Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
                Uri contentUri = Uri.fromFile(dumpFile);
                mediaScanIntent.setData(contentUri);
                c.sendBroadcast(mediaScanIntent);
            } catch (FileNotFoundException e2) {
                e2.printStackTrace();
            }
            defaultUEH.uncaughtException(t, e);
        }
    });

    mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    mSharedPreferences.registerOnSharedPreferenceChangeListener(this);
    prefUnitType = mSharedPreferences.getBoolean(Const.KEY_PREF_UNIT_TYPE, prefUnitType);
    prefKnots = mSharedPreferences.getBoolean(Const.KEY_PREF_KNOTS, prefKnots);
    prefCoord = Integer
            .valueOf(mSharedPreferences.getString(Const.KEY_PREF_COORD, Integer.toString(prefCoord)));
    prefUtc = mSharedPreferences.getBoolean(Const.KEY_PREF_UTC, prefUtc);
    prefCid = mSharedPreferences.getBoolean(Const.KEY_PREF_CID, prefCid);
    prefCid2 = mSharedPreferences.getBoolean(Const.KEY_PREF_CID2, prefCid2);
    prefWifiSort = Integer
            .valueOf(mSharedPreferences.getString(Const.KEY_PREF_WIFI_SORT, Integer.toString(prefWifiSort)));
    prefMapOffline = mSharedPreferences.getBoolean(Const.KEY_PREF_MAP_OFFLINE, prefMapOffline);
    prefMapPath = mSharedPreferences.getString(Const.KEY_PREF_MAP_PATH, prefMapPath);

    ActionBar actionBar = getSupportActionBar();

    setContentView(R.layout.activity_main);

    // Find out default screen orientation
    Configuration config = getResources().getConfiguration();
    WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
    int rot = wm.getDefaultDisplay().getRotation();
    isWideScreen = (config.orientation == Configuration.ORIENTATION_LANDSCAPE
            && (rot == Surface.ROTATION_0 || rot == Surface.ROTATION_180)
            || config.orientation == Configuration.ORIENTATION_PORTRAIT
                    && (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270));
    Log.d(TAG, "isWideScreen=" + Boolean.toString(isWideScreen));

    // Create the adapter that will return a fragment for each of the
    // primary sections of the app.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    Context ctx = new ContextThemeWrapper(getApplication(), R.style.AppTheme);
    mTabLayout = new TabLayout(ctx);
    LinearLayout.LayoutParams mTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    mTabLayout.setLayoutParams(mTabLayoutParams);

    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
        TabLayout.Tab newTab = mTabLayout.newTab();
        newTab.setIcon(mSectionsPagerAdapter.getPageIcon(i));
        mTabLayout.addTab(newTab);
    }

    actionBar.setDisplayShowCustomEnabled(true);
    actionBar.setCustomView(mTabLayout);

    mTabLayout.setOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager));
    mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(mTabLayout));

    // This is needed by the mapsforge library.
    AndroidGraphicFactory.createInstance(this.getApplication());

    // Get system services for event delivery
    locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    mOrSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
    mAccSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    mGyroSensor = sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
    mMagSensor = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
    mLightSensor = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
    mProximitySensor = sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
    mPressureSensor = sensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE);
    mHumiditySensor = sensorManager.getDefaultSensor(Sensor.TYPE_RELATIVE_HUMIDITY);
    mTempSensor = sensorManager.getDefaultSensor(Sensor.TYPE_AMBIENT_TEMPERATURE);
    telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
}

From source file:com.github.nukesparrow.htmlunit.DebuggingWebConnection.java

public void writeHtml(PrintStream out) {
    int i = TEMPLATE.indexOf(TEMPLATE_MARK);

    if (i == -1) {
        throw new IllegalStateException();
    }// ww  w  .  j  ava 2  s . c o  m

    out.print(TEMPLATE.substring(0, i));

    for (final Object element : events.toArray()) {
        synchronized (element) {
            String content = JSONValue.toJSONString(element);
            String encoding = null;

            String cc = content.toLowerCase();
            if (cc.contains("</script>") || cc.contains("<!--")) {
                encoding = "base64";
                try {
                    content = Base64.encodeBase64String(content.getBytes("UTF-8"));
                } catch (UnsupportedEncodingException ex) {
                    throw new RuntimeException(ex);
                }
            }

            out.append("<script type=\"text/x-event-json\""
                    + (encoding == null ? "" : " encoding=\"" + encoding + "\"") + ">" + content
                    + "</script>\n");
        }
    }

    out.print(TEMPLATE.substring(i + TEMPLATE_MARK.length()));
}

From source file:com.buildml.main.CliUtils.java

/**
 * A helper method, called exclusively by printActionSet(). This method calls itself recursively
 * as it traverses the ActionSet's tree structure.
 * //from  w  ww .  j  a v a  2 s.co  m
 * @param outStream The PrintStream on which to display the output.
 * @param buildStore The database containing file, action and package information.
 * @param actionId The ID of the action we're currently displaying (at this level of recursion).
 * @param resultActionSet The full set of actions to be displayed (the result of some previous query).
 * @param filterActionSet The set of actions to actually be displayed (for post-filtering the query results).
 * @param outputFormat The way in which the actions should be formatted.
 * @param showPkgs Set to true if we should display package names.
 * @param indentLevel The number of spaces to indent this action by (at this recursion level).
 */
private static void printActionSetHelper(PrintStream outStream, IBuildStore buildStore, int actionId,
        ActionSet resultActionSet, ActionSet filterActionSet, DisplayWidth outputFormat, boolean showPkgs,
        int indentLevel) {

    IActionMgr actionMgr = buildStore.getActionMgr();
    IFileMgr fileMgr = buildStore.getFileMgr();
    IPackageMgr pkgMgr = buildStore.getPackageMgr();
    IPackageMemberMgr pkgMemberMgr = buildStore.getPackageMemberMgr();

    /* 
     * Display the current action, at the appropriate indentation level. The format is:
     * 
     * - Action 1 (/home/psmith/t/cvs-1.11.23)
      *     if test ! -f config.h; then rm -f stamp-h1; emake  stamp-h1; else :;
      *     
      * -- Action 2 (/home/psmith/t/cvs-1.11.23)
      *      failcom='exit 1'; for f in x $MAKEFLAGS; do case $f in *=* | --[!k]*);; \
      *
      * Where Action 1 is the parent of Action 2.
      */

    /* is this action in the ActionSet to be printed? If not, terminate recursion */
    if (!(((resultActionSet == null) || (resultActionSet.isMember(actionId)))
            && ((filterActionSet == null) || (filterActionSet.isMember(actionId))))) {
        return;
    }

    /* 
     * Fetch the action's command string (if there is one). It can either be
     * in short format (on a single line), or a full string (possibly multiple lines)
     */
    String command = (String) actionMgr.getSlotValue(actionId, IActionMgr.COMMAND_SLOT_ID);
    if (command == null) {
        command = "<unknown command>";
    } else if (outputFormat == DisplayWidth.ONE_LINE) {
        command = ShellCommandUtils.getCommandSummary(command, getColumnWidth() - indentLevel - 3);
    }

    /* fetch the name of the directory the action was executed in */
    int actionDirId = (Integer) actionMgr.getSlotValue(actionId, IActionMgr.DIRECTORY_SLOT_ID);
    String actionDirName = fileMgr.getPathName(actionDirId);

    /* display the correct number of "-" characters */
    for (int i = 0; i != indentLevel; i++) {
        outStream.append('-');
    }
    outStream.print(" Action " + actionId + " (" + actionDirName);

    /* if requested, display the action's package name */
    if (showPkgs) {
        PackageDesc pkg = pkgMemberMgr.getPackageOfMember(IPackageMemberMgr.TYPE_ACTION, actionId);
        if (pkg == null) {
            outStream.print(" - Invalid action");
        } else {
            String pkgName = pkgMgr.getName(pkg.pkgId);
            if (pkgName == null) {
                outStream.print(" - Invalid package");
            } else {
                outStream.print(" - " + pkgName);
            }
        }
    }
    outStream.println(")");

    /* display the action's command string. Each line must be indented appropriately */
    if (outputFormat != DisplayWidth.NOT_WRAPPED) {
        PrintUtils.indentAndWrap(outStream, command, indentLevel + 3, getColumnWidth());
        outStream.println();
    } else {
        outStream.println(command);
    }

    /* recursively call ourselves to display each of our children */
    Integer children[] = actionMgr.getChildren(actionId);
    for (int i = 0; i < children.length; i++) {
        printActionSetHelper(outStream, buildStore, children[i], resultActionSet, filterActionSet, outputFormat,
                showPkgs, indentLevel + 1);
    }

}

From source file:gov.nasa.ensemble.dictionary.nddl.NumericResourceTranslator.java

@Override
public void writeCompats(PrintStream oStrm) {

    // PHM 10/22/2012 Define global constants needed for
    // numeric compats More useful to see here than buried in
    // writeObjects. TODO: prune if not in resource effect.
    for (Constant constant : allConstants) {
        writeConstant(oStrm, constant);/*from  w  w w. ja  v a  2 s  . c  o  m*/
    }
    oStrm.printf("\n");

    // PHM 03/12/2013 Need an incon compat to set the
    // numerical resources. Omit the passive/active guards
    // for now, so only one.
    oStrm.print(
            "InitialConds::incon {\n" + "  if (scheduled == true) {\n" + "        eq(inconStart, start);\n\n");

    for (ENumericResourceDef res : resourceDefs_) {
        String startVar = NDDLUtil.escape("init_" + res.getName());
        String resName = NDDLUtil.escape(res.getName());
        oStrm.printf("\n" + "\t starts(%s.produce %s);\n" + "\t eq(%s.quantity, _%s);\n", resName, startVar,
                startVar, resName);
    }
    oStrm.print("    }\n  }\n\n");

    // PHM 10/22/2012 The compats are currently not legal
    // nddl, so put comment around them. They could be
    // manually rewritten.

    // PHM 04/12/2013 The compats are now legal but formulas
    // are limited to params and negations of params.
    // Intermediate variables should be used to evaluate
    // javascript quantities in SPIFe.

    // oStrm.printf("/* COMPATS FOR NUMERIC RESOURCES\n\n");

    for (ActResourceEffect are : actResourceEffects_) {
        for (ResourceEffect effect : are.effects) {
            if ((effect.startEffect != null) && (effect.startEffect.length() > 0)) {
                ST compat = createCompat(are.activity, effect, effect.startEffect, "start");
                oStrm.append(compat.render());
            }
            if ((effect.endEffect != null) && (effect.endEffect.length() > 0)) {
                ST compat = createCompat(are.activity, effect, effect.endEffect, "end");
                oStrm.append(compat.render());
            }
        }
    }

    // oStrm.printf("\n*/");
}

From source file:com.databasepreservation.cli.CLI.java

private void printHelp(PrintStream printStream) {
    StringBuilder out = new StringBuilder();

    out.append("Database Preservation Toolkit").append(MiscUtils.APP_NAME_AND_VERSION)
            .append("\nMore info: http://www.database-preservation.com").append("\n")
            .append("Usage: dbptk [plugin] <importModule> [import module options] <exportModule> [export module options]\n\n");

    ArrayList<DatabaseModuleFactory> modulesList = new ArrayList<DatabaseModuleFactory>(factories);
    Collections.sort(modulesList, new DatabaseModuleFactoryNameComparator());
    out.append("## Plugin:\n");
    out.append(/*from w  ww  . ja  v  a 2s .c o m*/
            "    -p, --plugin=plugin.jar    (optional) the file containing a plugin module. Several plugins can be specified, separated by a semi-colon (;)\n");

    out.append("\n## Available import modules: -i <module>, --import=module\n");
    for (DatabaseModuleFactory factory : modulesList) {
        if (factory.producesImportModules()) {
            try {
                out.append(printModuleHelp("Import module: " + factory.getModuleName(), "i", "import",
                        factory.getImportModuleParameters()));
            } catch (OperationNotSupportedException e) {
                LOGGER.debug("This should not occur a this point", e);
            }
        }
    }

    out.append("\n## Available export modules: -e <module>, --export=module\n");
    for (DatabaseModuleFactory factory : modulesList) {
        if (factory.producesExportModules()) {
            try {
                out.append(printModuleHelp("Export module: " + factory.getModuleName(), "e", "export",
                        factory.getExportModuleParameters()));
            } catch (OperationNotSupportedException e) {
                LOGGER.debug("This should not occur a this point", e);
            }
        }
    }

    printStream.append(out).flush();
}

From source file:com.vonglasow.michael.satstat.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    defaultUEH = Thread.getDefaultUncaughtExceptionHandler();

    Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
        public void uncaughtException(Thread t, Throwable e) {
            Context c = getApplicationContext();
            File dumpDir = c.getExternalFilesDir(null);
            File dumpFile = new File(dumpDir, "satstat-" + System.currentTimeMillis() + ".log");
            PrintStream s;
            try {
                InputStream buildInStream = getResources().openRawResource(R.raw.build);
                s = new PrintStream(dumpFile);
                s.append("SatStat build: ");

                int i;
                try {
                    i = buildInStream.read();
                    while (i != -1) {
                        s.write(i);//w  w  w . j  av a2  s.c o m
                        i = buildInStream.read();
                    }
                    buildInStream.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }

                s.append("\n\n");
                e.printStackTrace(s);
                s.flush();
                s.close();
            } catch (FileNotFoundException e2) {
                e2.printStackTrace();
            }
            defaultUEH.uncaughtException(t, e);
        }
    });

    mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    mSharedPreferences.registerOnSharedPreferenceChangeListener(this);

    final ActionBar actionBar = getActionBar();

    setContentView(R.layout.activity_main);

    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Find out default screen orientation
    Configuration config = getResources().getConfiguration();
    WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
    int rot = wm.getDefaultDisplay().getRotation();
    isWideScreen = (config.orientation == Configuration.ORIENTATION_LANDSCAPE
            && (rot == Surface.ROTATION_0 || rot == Surface.ROTATION_180)
            || config.orientation == Configuration.ORIENTATION_PORTRAIT
                    && (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270));
    Log.d("MainActivity", "isWideScreen=" + Boolean.toString(isWideScreen));

    // compact action bar
    int dpX = (int) (this.getResources().getDisplayMetrics().widthPixels
            / this.getResources().getDisplayMetrics().density);
    /*
     * This is a crude way to ensure a one-line action bar with tabs
     * (not a drop-down list) and home (incon) and title only if there
     * is space, depending on screen width:
     * divide screen in units of 64 dp
     * each tab requires 1 unit, home and menu require slightly less,
     * title takes up approx. 2.5 units in portrait,
     * home and title are about 2 units wide in landscape
     */
    if (dpX < 192) {
        // just enough space for drop-down list and menu
        actionBar.setDisplayShowHomeEnabled(false);
        actionBar.setDisplayShowTitleEnabled(false);
    } else if (dpX < 320) {
        // not enough space for four tabs, but home will fit next to list
        actionBar.setDisplayShowHomeEnabled(true);
        actionBar.setDisplayShowTitleEnabled(false);
    } else if (dpX < 384) {
        // just enough space for four tabs
        actionBar.setDisplayShowHomeEnabled(false);
        actionBar.setDisplayShowTitleEnabled(false);
    } else if ((dpX < 448) || ((config.orientation == Configuration.ORIENTATION_PORTRAIT) && (dpX < 544))) {
        // space for four tabs and home, but not title
        actionBar.setDisplayShowHomeEnabled(true);
        actionBar.setDisplayShowTitleEnabled(false);
    } else {
        // ample space for home, title and all four tabs
        actionBar.setDisplayShowHomeEnabled(true);
        actionBar.setDisplayShowTitleEnabled(true);
    }
    setEmbeddedTabs(actionBar, true);

    providerLocations = new HashMap<String, Location>();

    mAvailableProviderStyles = new ArrayList<String>(Arrays.asList(LOCATION_PROVIDER_STYLES));

    providerStyles = new HashMap<String, String>();
    providerAppliedStyles = new HashMap<String, String>();

    providerInvalidationHandler = new Handler();
    providerInvalidators = new HashMap<String, Runnable>();

    // Create the adapter that will return a fragment for each of the three
    // primary sections of the app.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(this);

    // Add tabs, specifying the tab's text and TabListener
    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
        actionBar.addTab(actionBar.newTab()
                //.setText(mSectionsPagerAdapter.getPageTitle(i))
                .setIcon(mSectionsPagerAdapter.getPageIcon(i)).setTabListener(this));
    }

    // This is needed by the mapsforge library.
    AndroidGraphicFactory.createInstance(this.getApplication());

    // Get system services for event delivery
    mLocationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    mOrSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
    mAccSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    mGyroSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
    mMagSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
    mLightSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
    mProximitySensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
    mPressureSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE);
    mHumiditySensor = mSensorManager.getDefaultSensor(Sensor.TYPE_RELATIVE_HUMIDITY);
    mTempSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_AMBIENT_TEMPERATURE);
    mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    mConnectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);

    mAccSensorRes = getSensorDecimals(mAccSensor, mAccSensorRes);
    mGyroSensorRes = getSensorDecimals(mGyroSensor, mGyroSensorRes);
    mMagSensorRes = getSensorDecimals(mMagSensor, mMagSensorRes);
    mLightSensorRes = getSensorDecimals(mLightSensor, mLightSensorRes);
    mProximitySensorRes = getSensorDecimals(mProximitySensor, mProximitySensorRes);
    mPressureSensorRes = getSensorDecimals(mPressureSensor, mPressureSensorRes);
    mHumiditySensorRes = getSensorDecimals(mHumiditySensor, mHumiditySensorRes);
    mTempSensorRes = getSensorDecimals(mTempSensor, mTempSensorRes);

    networkTimehandler = new Handler();
    networkTimeRunnable = new Runnable() {
        @Override
        public void run() {
            int newNetworkType = mTelephonyManager.getNetworkType();
            if (getNetworkGeneration(newNetworkType) != mLastNetworkGen)
                onNetworkTypeChanged(newNetworkType);
            else
                networkTimehandler.postDelayed(this, NETWORK_REFRESH_DELAY);
        }
    };

    wifiTimehandler = new Handler();
    wifiTimeRunnable = new Runnable() {

        @Override
        public void run() {
            mWifiManager.startScan();
            wifiTimehandler.postDelayed(this, WIFI_REFRESH_DELAY);
        }
    };

    updateLocationProviderStyles();
}

From source file:com.perpetumobile.bit.orm.cassandra.CliMain.java

/**
 * Creates a CLI script to create the Keyspace it's Column Families
 *
 * @param output StringBuilder to write to.
 * @param ksDef KsDef to create the cli script for.
 *///from  w ww . ja va 2  s.c  om
private void showKeyspace(PrintStream output, KsDef ksDef) {
    output.append("create keyspace ").append(CliUtils.maybeEscapeName(ksDef.name));

    writeAttr(output, true, "placement_strategy",
            normaliseType(ksDef.strategy_class, "org.apache.cassandra.locator"));

    if (ksDef.strategy_options != null && !ksDef.strategy_options.isEmpty()) {
        final StringBuilder opts = new StringBuilder();
        opts.append("{");
        String prefix = "";
        for (Map.Entry<String, String> opt : ksDef.strategy_options.entrySet()) {
            opts.append(prefix + CliUtils.escapeSQLString(opt.getKey()) + " : "
                    + CliUtils.escapeSQLString(opt.getValue()));
            prefix = ", ";
        }
        opts.append("}");
        writeAttrRaw(output, false, "strategy_options", opts.toString());
    }

    writeAttr(output, false, "durable_writes", ksDef.durable_writes);

    output.append(";").append(NEWLINE);
    output.append(NEWLINE);

    output.append("use " + CliUtils.maybeEscapeName(ksDef.name) + ";");
    output.append(NEWLINE);
    output.append(NEWLINE);

    Collections.sort(ksDef.cf_defs, new CfDefNamesComparator());
    for (CfDef cfDef : ksDef.cf_defs)
        showColumnFamily(output, cfDef);
    output.append(NEWLINE);
    output.append(NEWLINE);
}

From source file:com.perpetumobile.bit.orm.cassandra.CliMain.java

private void writeAttrRaw(PrintStream output, boolean first, String name, String value) {
    output.append(NEWLINE).append(TAB);
    output.append(first ? "with " : "and ");
    output.append(name).append(" = ");
    output.append(value);//w w  w .j av  a  2s .co  m
}

From source file:com.perpetumobile.bit.orm.cassandra.CliMain.java

/**
 * Writes the supplied ColumnDef to the StringBuilder as a cli script.
 *
 * @param output The File to write to.// w  w w  .j a  v  a  2 s .  c  o  m
 * @param cfDef  The CfDef as a source for comparator/validator
 * @param colDef The Column Definition to export
 */
private void showColumnMeta(PrintStream output, CfDef cfDef, ColumnDef colDef) {
    output.append(NEWLINE + TAB + TAB + "{");

    final AbstractType<?> comparator = getFormatType(
            cfDef.column_type.equals("Super") ? cfDef.subcomparator_type : cfDef.comparator_type);
    output.append(
            "column_name : '" + CliUtils.escapeSQLString(comparator.getString(colDef.name)) + "'," + NEWLINE);
    String validationClass = normaliseType(colDef.validation_class, "org.apache.cassandra.db.marshal");
    output.append(TAB + TAB + "validation_class : " + CliUtils.escapeSQLString(validationClass));
    if (colDef.isSetIndex_name()) {
        output.append(",").append(NEWLINE)
                .append(TAB + TAB + "index_name : '" + CliUtils.escapeSQLString(colDef.index_name) + "',"
                        + NEWLINE)
                .append(TAB + TAB + "index_type : "
                        + CliUtils.escapeSQLString(Integer.toString(colDef.index_type.getValue())));

        if (colDef.index_options != null && !colDef.index_options.isEmpty()) {
            output.append(",").append(NEWLINE);
            output.append(TAB + TAB + "index_options : {" + NEWLINE);
            int numOpts = colDef.index_options.size();
            for (Map.Entry<String, String> entry : colDef.index_options.entrySet()) {
                String option = CliUtils.escapeSQLString(entry.getKey());
                String optionValue = CliUtils.escapeSQLString(entry.getValue());

                output.append(TAB + TAB + TAB).append("'" + option + "' : '").append(optionValue).append("'");

                if (--numOpts > 0)
                    output.append(",").append(NEWLINE);
            }
            output.append("}");
        }
    }
    output.append("}");
}