一:git clone https://android.googlesource.com/platform/packages/inputmethods/PinyinIME
二:https://android.googlesource.com/platform/packages/inputmethods/PinyinIME/
package com.jk.binderjava;
import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class HttpsTest extends AppCompatActivity {
private final static String TAG = "HttpsTest";
private Button mBtnTstDownload = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_https_test);
mBtnTstDownload = findViewById(R.id.tstdownload);
mBtnTstDownload.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d(TAG, "onClick: ");
new Thread(new Runnable() {
@Override
public void run() {
dohttpsdownload();
}
}).start();
}
});
}
void dohttpsdownload() {
Log.d(TAG, "dohttpsdownload: start =================");
HttpURLConnection connection = null;
try {
connection = (HttpURLConnection) new URL("https://tsp-pro-vod.obs.cn-north-1.myhuaweicloud.com/4e77a985f9a82c2acaad0ce7ebd2f69a.mp4").openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("Content-Type", "application/json");
connection.setConnectTimeout(1000 * 5);
connection.setReadTimeout(1000 * 5);
connection.connect();
int responseCode = connection.getResponseCode();
Log.d(TAG, "dohttpsdownload: end =====================");
Log.d(TAG, "onClick: response code : {}" + responseCode);
} catch (IOException e) {
e.printStackTrace();
}
try {
Log.d(TAG, "dohttpsdownload: save file =================== start");
if (connection.getResponseCode() == 200) {
// String result = streamToString(connection.getInputStream());
File file = new File(Environment.getExternalStorageDirectory(), "a.mp4");
stream2File(file.getAbsolutePath(), connection.getInputStream());
}
Log.d(TAG, "dohttpsdownload: save file =================== end");
} catch (IOException e) {
e.printStackTrace();
}
}
void stream2File(String destination, InputStream is) {
int index;
byte[] bytes = new byte[1024];
FileOutputStream destFile = null;
try {
destFile = new FileOutputStream(destination);
while ((index = is.read(bytes)) != -1) {
destFile.write(bytes, 0, index);
destFile.flush();
}
destFile.close();
is.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
Log.d(TAG, "writeToLocal: ", e);
}
}
public String streamToString(InputStream is) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = 0;
while ((len = is.read(buffer)) != -1) {
baos.write(buffer, 0, len);
}
baos.close();
is.close();
byte[] byteArray = baos.toByteArray();
return new String(byteArray);
} catch (Exception e) {
Log.e(TAG, e.toString());
return null;
}
}
}