• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Javaプログラミングの練習です。


Commit MetaInfo

Revision55b04395847b5568be6b9192eeaf6d55e1ebf8c0 (tree)
Time2016-07-03 14:37:58
Authorkurukurupapa <gootarapapa@gmai...>
Commiterkurukurupapa

Log Message

URLエンコード処理を追加。

Change Summary

Incremental Difference

--- /dev/null
+++ b/tryjava1_4/src/main/java/com/tryjava/net/UrlEncodeJava.java
@@ -0,0 +1,32 @@
1+package com.tryjava.net;
2+
3+import java.io.UnsupportedEncodingException;
4+import java.net.URLDecoder;
5+import java.net.URLEncoder;
6+
7+/**
8+ * URLエンコードを使ってみる。
9+ */
10+public class UrlEncodeJava {
11+
12+ public static void main(String[] args) {
13+ new UrlEncodeJava().run();
14+ }
15+
16+ public void run() {
17+ step01();
18+ }
19+
20+ private void step01() {
21+ try {
22+ String encoded = URLEncoder.encode("https://www.tryjava.com/path/name?key1=value1&key2=おはよう#name", "UTF-8");
23+ System.out.println(encoded);
24+
25+ String decoded = URLDecoder.decode(encoded, "UTF-8");
26+ System.out.println(decoded);
27+
28+ } catch (UnsupportedEncodingException e) {
29+ throw new RuntimeException(e);
30+ }
31+ }
32+}
--- /dev/null
+++ b/tryjava1_4/src/test/java/com/tryjava/net/UrlEncodeJavaTest.java
@@ -0,0 +1,26 @@
1+package com.tryjava.net;
2+
3+import junit.framework.TestCase;
4+
5+public class UrlEncodeJavaTest extends TestCase {
6+
7+ private UrlEncodeJava sut;
8+
9+ public void setUp() throws Exception {
10+ super.setUp();
11+ System.out.println("--- setUp ---");
12+
13+ sut = new UrlEncodeJava();
14+ }
15+
16+ public void testRun() {
17+ System.out.println("--- test ---");
18+ // 準備
19+
20+ // テスト実行
21+ sut.run();
22+
23+ // 検証
24+ // 例外が発生しなければOK
25+ }
26+}
--- /dev/null
+++ b/tryjava5/src/main/java/com/tryjava/net/UrlEncodeJava.java
@@ -0,0 +1,32 @@
1+package com.tryjava.net;
2+
3+import java.io.UnsupportedEncodingException;
4+import java.net.URLDecoder;
5+import java.net.URLEncoder;
6+
7+/**
8+ * URLエンコードを使ってみる。
9+ */
10+public class UrlEncodeJava {
11+
12+ public static void main(String[] args) {
13+ new UrlEncodeJava().run();
14+ }
15+
16+ public void run() {
17+ step01();
18+ }
19+
20+ private void step01() {
21+ try {
22+ String encoded = URLEncoder.encode("https://www.tryjava.com/path/name?key1=value1&key2=おはよう#name", "UTF-8");
23+ System.out.println(encoded);
24+
25+ String decoded = URLDecoder.decode(encoded, "UTF-8");
26+ System.out.println(decoded);
27+
28+ } catch (UnsupportedEncodingException e) {
29+ throw new RuntimeException(e);
30+ }
31+ }
32+}
--- /dev/null
+++ b/tryjava5/src/test/java/com/tryjava/net/UrlEncodeJavaTest.java
@@ -0,0 +1,34 @@
1+package com.tryjava.net;
2+
3+import java.io.IOException;
4+
5+import org.junit.Before;
6+import org.junit.Rule;
7+import org.junit.Test;
8+import org.junit.rules.TestName;
9+
10+public class UrlEncodeJavaTest {
11+
12+ @Rule
13+ public TestName testName = new TestName();
14+
15+ private UrlEncodeJava sut;
16+
17+ @Before
18+ public void setUp() throws Exception {
19+ System.out.println("--- " + testName.getMethodName() + " ---");
20+ sut = new UrlEncodeJava();
21+ }
22+
23+ @Test
24+ public void testRun() throws IOException {
25+ // 準備
26+
27+ // テスト実行
28+ sut.run();
29+
30+ // 検証
31+ // 例外が発生しなければOK
32+ }
33+
34+}
--- /dev/null
+++ b/tryjava6/src/main/java/com/tryjava/net/UrlEncodeJava.java
@@ -0,0 +1,32 @@
1+package com.tryjava.net;
2+
3+import java.io.UnsupportedEncodingException;
4+import java.net.URLDecoder;
5+import java.net.URLEncoder;
6+
7+/**
8+ * URLエンコードを使ってみる。
9+ */
10+public class UrlEncodeJava {
11+
12+ public static void main(String[] args) {
13+ new UrlEncodeJava().run();
14+ }
15+
16+ public void run() {
17+ step01();
18+ }
19+
20+ private void step01() {
21+ try {
22+ String encoded = URLEncoder.encode("https://www.tryjava.com/path/name?key1=value1&key2=おはよう#name", "UTF-8");
23+ System.out.println(encoded);
24+
25+ String decoded = URLDecoder.decode(encoded, "UTF-8");
26+ System.out.println(decoded);
27+
28+ } catch (UnsupportedEncodingException e) {
29+ throw new RuntimeException(e);
30+ }
31+ }
32+}
--- /dev/null
+++ b/tryjava6/src/test/java/com/tryjava/net/UrlEncodeJavaTest.java
@@ -0,0 +1,34 @@
1+package com.tryjava.net;
2+
3+import java.io.IOException;
4+
5+import org.junit.Before;
6+import org.junit.Rule;
7+import org.junit.Test;
8+import org.junit.rules.TestName;
9+
10+public class UrlEncodeJavaTest {
11+
12+ @Rule
13+ public TestName testName = new TestName();
14+
15+ private UrlEncodeJava sut;
16+
17+ @Before
18+ public void setUp() throws Exception {
19+ System.out.println("--- " + testName.getMethodName() + " ---");
20+ sut = new UrlEncodeJava();
21+ }
22+
23+ @Test
24+ public void testRun() throws IOException {
25+ // 準備
26+
27+ // テスト実行
28+ sut.run();
29+
30+ // 検証
31+ // 例外が発生しなければOK
32+ }
33+
34+}
--- /dev/null
+++ b/tryjava8/src/main/java/com/tryjava/net/UrlEncodeJava.java
@@ -0,0 +1,32 @@
1+package com.tryjava.net;
2+
3+import java.io.UnsupportedEncodingException;
4+import java.net.URLDecoder;
5+import java.net.URLEncoder;
6+
7+/**
8+ * URLエンコードを使ってみる。
9+ */
10+public class UrlEncodeJava {
11+
12+ public static void main(String[] args) {
13+ new UrlEncodeJava().run();
14+ }
15+
16+ public void run() {
17+ step01();
18+ }
19+
20+ private void step01() {
21+ try {
22+ String encoded = URLEncoder.encode("https://www.tryjava.com/path/name?key1=value1&key2=おはよう#name", "UTF-8");
23+ System.out.println(encoded);
24+
25+ String decoded = URLDecoder.decode(encoded, "UTF-8");
26+ System.out.println(decoded);
27+
28+ } catch (UnsupportedEncodingException e) {
29+ throw new RuntimeException(e);
30+ }
31+ }
32+}
--- /dev/null
+++ b/tryjava8/src/test/java/com/tryjava/net/UrlEncodeJavaTest.java
@@ -0,0 +1,34 @@
1+package com.tryjava.net;
2+
3+import java.io.IOException;
4+
5+import org.junit.Before;
6+import org.junit.Rule;
7+import org.junit.Test;
8+import org.junit.rules.TestName;
9+
10+public class UrlEncodeJavaTest {
11+
12+ @Rule
13+ public TestName testName = new TestName();
14+
15+ private UrlEncodeJava sut;
16+
17+ @Before
18+ public void setUp() throws Exception {
19+ System.out.println("--- " + testName.getMethodName() + " ---");
20+ sut = new UrlEncodeJava();
21+ }
22+
23+ @Test
24+ public void testRun() throws IOException {
25+ // 準備
26+
27+ // テスト実行
28+ sut.run();
29+
30+ // 検証
31+ // 例外が発生しなければOK
32+ }
33+
34+}