Skip to content

Commit baf5b75

Browse files
Initial commit
0 parents  commit baf5b75

File tree

46 files changed

+1053
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1053
-0
lines changed

.gitignore

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild
14+
.cxx

.idea/codeStyles/Project.xml

+116
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

+21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/jarRepositories.xml

+25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations.xml

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Advanced_HttpURLConnection/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
apply plugin: 'com.android.library'
2+
3+
android {
4+
compileSdkVersion 29
5+
buildToolsVersion "29.0.3"
6+
7+
defaultConfig {
8+
minSdkVersion 14
9+
targetSdkVersion 29
10+
versionCode 1
11+
versionName "1.0"
12+
13+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
14+
consumerProguardFiles "consumer-rules.pro"
15+
}
16+
17+
buildTypes {
18+
release {
19+
minifyEnabled false
20+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
21+
}
22+
}
23+
}
24+
25+
dependencies {
26+
implementation fileTree(dir: "libs", include: ["*.jar"])
27+
implementation 'androidx.appcompat:appcompat:1.1.0'
28+
testImplementation 'junit:junit:4.12'
29+
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
30+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
31+
32+
}

Advanced_HttpURLConnection/consumer-rules.pro

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.vishnusivadas.advanced_httpurlconnection;
2+
3+
import android.content.Context;
4+
5+
import androidx.test.platform.app.InstrumentationRegistry;
6+
import androidx.test.ext.junit.runners.AndroidJUnit4;
7+
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
11+
import static org.junit.Assert.*;
12+
13+
/**
14+
* Instrumented test, which will execute on an Android device.
15+
*
16+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
17+
*/
18+
@RunWith(AndroidJUnit4.class)
19+
public class ExampleInstrumentedTest {
20+
@Test
21+
public void useAppContext() {
22+
// Context of the app under test.
23+
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24+
assertEquals("com.vishnusivadas.advanced_httpurlconnection.test", appContext.getPackageName());
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.vishnusivadas.advanced_httpurlconnection">
3+
4+
/
5+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.vishnusivadas.advanced_httpurlconnection;
2+
3+
import android.util.Log;
4+
5+
import java.io.BufferedReader;
6+
import java.io.IOException;
7+
import java.io.InputStream;
8+
import java.io.InputStreamReader;
9+
import java.net.HttpURLConnection;
10+
import java.net.URL;
11+
12+
public class FetchData extends Thread {
13+
private String url;
14+
String data = "Empty";
15+
16+
public FetchData(String url) {
17+
this.url = url;
18+
}
19+
20+
@Override
21+
public void run() {
22+
Log.i("FetchData"+" State: ", "Start");
23+
try {
24+
URL url = new URL(this.url);
25+
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
26+
InputStream inputStream = httpURLConnection.getInputStream();
27+
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
28+
StringBuilder result = new StringBuilder();
29+
String data;
30+
while ((data = bufferedReader.readLine()) != null) {
31+
result.append(data);
32+
}
33+
bufferedReader.close();
34+
inputStream.close();
35+
httpURLConnection.disconnect();
36+
setData(result.toString());
37+
} catch (IOException e) {
38+
setData(e.toString());
39+
}
40+
}
41+
42+
public String getValue() {
43+
while (true) {
44+
if (!this.isAlive()) {
45+
return this.getData();
46+
}
47+
}
48+
}
49+
50+
public void setData(String data) {
51+
this.data = data;
52+
}
53+
54+
55+
public String getData() {
56+
return data;
57+
}
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.vishnusivadas.advanced_httpurlconnection;
2+
3+
import org.junit.Test;
4+
5+
import static org.junit.Assert.*;
6+
7+
/**
8+
* Example local unit test, which will execute on the development machine (host).
9+
*
10+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
11+
*/
12+
public class ExampleUnitTest {
13+
@Test
14+
public void addition_isCorrect() {
15+
assertEquals(4, 2 + 2);
16+
}
17+
}

app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

0 commit comments

Comments
 (0)