Sunday, November 30, 2014

how to used wget to quickly download many files

1.what

i need used wget to batch download many files.

then i used excel input :

1 row 1 column text: http://example.com/1.txt

2 row 1 column text: http://example.com/2.txt

then draw  these two rows to 100 rows,so it will generate from http://example.com/1.txt to http://example.com/100.txt.

after that,copy this all content,then paste them to text editor for download.txt 

2.how

command

>wget -i download.txt --content-disposition



download.txt:



http://example.com/1.txt
http://example.com/2.txt
// more file here...
http://example.com/100.txt




3. last:



thanks!

Tuesday, November 25, 2014

android get and post url content code sample

1.code

package com.pkrss.helper;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Map;

public class WebHelper {

public static String GetPageContent(String pageURL)
{
return _GetRemotePageContent("GET",pageURL,null);
}

public static String GetPostPageContent(String pageURL,Map<String,String> parameters)
{
return _GetRemotePageContent("POST",pageURL,parameters);
}

private static String _GetRemotePageContent(String method,String pageURL,Map<String,String> parameters)
{
String pageContent="";
BufferedReader in = null;
InputStreamReader isr = null;
InputStream is = null;
HttpURLConnection huc = null;

try
{

String strparam = "";

if(parameters != null){
for(Map.Entry<String,String> item : parameters.entrySet()){
if(strparam != "")
strparam += "&";
strparam += URLEncoder.encode(item.getKey(), "UTF-8") + "=" + URLEncoder.encode(item.getValue(), "UTF-8");
}
}

if(strparam!=null && strparam.length()>0 && method.equals("GET")){
if(pageURL.contains("?"))
pageURL += "&";
else
pageURL += "?";

pageURL += strparam;
}

URL url = new URL(pageURL);
huc = (HttpURLConnection)url.openConnection();

huc.setRequestMethod(method);

if(method.equals("POST")){
huc.setDoOutput(true);
huc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

OutputStreamWriter request = new OutputStreamWriter(huc.getOutputStream());

request.write(strparam);
request.flush();
request.close();
}

is = huc.getInputStream();

isr = new InputStreamReader(is,"UTF-8");
in = new BufferedReader(isr);
String line = null;
while(((line = in.readLine()) != null))
{
if(line.length()==0)
continue;
pageContent+=line; // + "\n";
}
}
catch (Exception e)
{
// e.printStackTrace();
}
finally
{
try
{
is.close(); isr.close();in.close();huc.disconnect();
}
catch (Exception e) {}
}
return pageContent;
}

}



2.Thanks

Monday, November 24, 2014

11-24 22:27:37.685: E/AndroidRuntime(8653): Caused by: java.lang.InstantiationException: can't instantiate class com.pkrss.webview_core.WebViewHasControlActivity$FragmentOptionsDialog; no empty constructor

1.error:

11-24 22:27:37.685: E/AndroidRuntime(8653): Caused by: java.lang.InstantiationException: can't instantiate class com.pkrss.webview_core.WebViewHasControlActivity$FragmentOptionsDialog; no empty constructor



2.fixed:



old:
public class WebViewHasControlActivity{
private class FragmentOptionsDialog extends FragmentBaseDialog {
public FragmentOptionsDialog(int arg1){
}
}
}

new:
public class WebViewHasControlActivity{
}

public class FragmentOptionsDialog extends FragmentBaseDialog {
public FragmentOptionsDialog(){
}

public void setArg1(int arg1){
}
}



3.Last



Thanks!

Android java enumerate JSONObject child items code

1.what

i need enumerate the JSONObject child item key and value by code

2.how

            JSONObject obj = null; // please set this not null value in first


Iterator<String> k = obj.keys();
String key;
Object value;
while(k.hasNext()){
key = k.next();
value = obj.opt(key);
if(value == null || obj.isNull(key))
continue;

if(value instanceof JSONArray){
JSONArray jary = (JSONArray)value;

}else if(value instanceof JSONObject){
JSONObject jobj = (JSONObject)value;

}else if(value instanceof String){
String s = (String)value;

}else if(value instanceof Long){
Long l = (Long)value;

}else if(value instanceof Integer){
Integer l = (Integer)value;

}else if(value instanceof Boolean){
Boolean b = (Boolean)value;

}else if(value instanceof Double){
Double d = (Double)value;
}
}



3.Last:



Thanks!

android Spinner setAdapter ArrayAdapter

1.xml:

<Spinner
android:id="@+id/spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content" />



2.code:



        List<String> _spinnerList;
ArrayAdapter _spinnerAdapter;

_spinnerList = new ArrayList<String>();
_spinnerAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, _spinnerList);


_spinnerList.add("1");
_spinnerList.add("2");
_spinnerList.add("3");

Spinner spinner = (Spinner)this.findViewById(R.id.spinner);
spinner.setAdapter(_spinnerAdapter);



3.event:



            _spinner.setOnItemSelectedListener(new OnItemSelectedListener(){

@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
// get content:
// String content = (String) parent.getItemAtPosition(position);
// or:
// String item = _spinnerList.get(position);
}

@Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub

}

});



4.last:



thanks!