From e8220845f222ab737d990d1d6165be7436e67252 Mon Sep 17 00:00:00 2001 From: Hugo Date: Sat, 13 Jun 2015 14:55:35 +0200 Subject: [PATCH] Supprime les stacktrace et remplace par des loggers --- .../java/com/amine/horaires/ShopDisplay.java | 38 +++++++++++-------- .../java/com/amine/horaires/ShopSearch.java | 15 ++++---- .../java/com/amine/horaires/ShopUpdate.java | 15 ++++---- .../java/com/amine/horaires/util/Parseur.java | 15 +++++--- .../java/com/amine/horaires/util/Utils.java | 14 ++++--- 5 files changed, 54 insertions(+), 43 deletions(-) diff --git a/Les Horaires/src/main/java/com/amine/horaires/ShopDisplay.java b/Les Horaires/src/main/java/com/amine/horaires/ShopDisplay.java index ae14cab..89ca5a6 100644 --- a/Les Horaires/src/main/java/com/amine/horaires/ShopDisplay.java +++ b/Les Horaires/src/main/java/com/amine/horaires/ShopDisplay.java @@ -9,6 +9,7 @@ import android.net.NetworkInfo; import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; +import android.util.Log; import android.view.Menu; import android.view.MenuInflater; import android.view.View; @@ -163,28 +164,37 @@ public class ShopDisplay extends OptionsActivity { @Override protected Bitmap doInBackground(String... params) { - URL url; + URL url = null; Bitmap b = null; + HttpURLConnection conn = null; + InputStream is = null; try { url = new URL(params[0]); - HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setDoInput(true); conn.connect(); - InputStream is = conn.getInputStream(); + is = conn.getInputStream(); b = BitmapFactory.decodeStream(is); - is.close(); conn.disconnect(); } catch (MalformedURLException e) { - e.printStackTrace(); + Log.e("ShopDisplay", "The API doesn't respond correctly. Asked url was "+url.toString(), e); } catch (ProtocolException e) { - e.printStackTrace(); + Log.e("ShopDisplay", "The protocol doesn't seems to be HTTP. Url was " + url.toString(), e); } catch (IOException e) { - e.printStackTrace(); + Log.e("ShopDisplay", "The image seems to be corrupt. Url was " + url.toString(), e); + } finally { + // Makes sure that the InputStream is closed after the app is finished using it. + if (is != null) + try { + is.close(); + } catch (IOException e) {} + if (conn != null) + conn.disconnect(); } return b; } @@ -201,9 +211,9 @@ public class ShopDisplay extends OptionsActivity { HttpURLConnection conn = null; InputStream is = null; String contentAsString = ""; - + URL url = null; try { - URL url = params[0]; + url = params[0]; conn = (HttpURLConnection) url.openConnection(); conn.setReadTimeout(10000 /* milliseconds */); conn.setConnectTimeout(15000 /* milliseconds */); @@ -221,19 +231,17 @@ public class ShopDisplay extends OptionsActivity { contentAsString = contentAsString + reader.nextLine(); } } catch (MalformedURLException e) { - e.printStackTrace(); + Log.e("ShopDisplay", "The API doesn't respond correctly. Asked url was " + url.toString(), e); } catch (ProtocolException e) { - e.printStackTrace(); + Log.e("ShopDisplay", "The protocol doesn't seems to be HTTP. Url was " + url.toString(), e); } catch (IOException e) { - e.printStackTrace(); + Log.e("ShopDisplay", "The API response is not readable. Url was " + url.toString(), e); } finally { // Makes sure that the InputStream is closed after the app is finished using it. if (is != null) try { is.close(); - } catch (IOException e) { - e.printStackTrace(); - } + } catch (IOException e) {} if (conn != null) conn.disconnect(); } diff --git a/Les Horaires/src/main/java/com/amine/horaires/ShopSearch.java b/Les Horaires/src/main/java/com/amine/horaires/ShopSearch.java index ae4f1d8..37a1c42 100644 --- a/Les Horaires/src/main/java/com/amine/horaires/ShopSearch.java +++ b/Les Horaires/src/main/java/com/amine/horaires/ShopSearch.java @@ -4,6 +4,7 @@ import android.content.Intent; import android.location.Location; import android.os.AsyncTask; import android.os.Bundle; +import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.EditText; @@ -81,9 +82,9 @@ public class ShopSearch extends OptionsActivity { HttpURLConnection conn = null; InputStream is = null; String contentAsString = ""; - + URL url = null; try { - URL url = params[0]; + url = params[0]; conn = (HttpURLConnection) url.openConnection(); conn.setReadTimeout(10000 /* milliseconds */); conn.setConnectTimeout(15000 /* milliseconds */); @@ -101,19 +102,17 @@ public class ShopSearch extends OptionsActivity { contentAsString = contentAsString + reader.nextLine(); } } catch (MalformedURLException e) { - e.printStackTrace(); + Log.e("ShopSearch", "The API doesn't respond correctly. Asked url was " + url.toString(), e); } catch (ProtocolException e) { - e.printStackTrace(); + Log.e("ShopSearch", "The protocol doesn't seems to be HTTP. Url was " + url.toString(), e); } catch (IOException e) { - e.printStackTrace(); + Log.e("ShopSearch", "The API response is not readable. Url was " + url.toString(), e); } finally { // Makes sure that the InputStream is closed after the app is finished using it. if (is != null) try { is.close(); - } catch (IOException e) { - e.printStackTrace(); - } + } catch (IOException e) {} if (conn != null) conn.disconnect(); } diff --git a/Les Horaires/src/main/java/com/amine/horaires/ShopUpdate.java b/Les Horaires/src/main/java/com/amine/horaires/ShopUpdate.java index a735c4f..a153d95 100644 --- a/Les Horaires/src/main/java/com/amine/horaires/ShopUpdate.java +++ b/Les Horaires/src/main/java/com/amine/horaires/ShopUpdate.java @@ -2,6 +2,7 @@ package com.amine.horaires; import android.os.AsyncTask; import android.os.Bundle; +import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.ListView; @@ -93,9 +94,9 @@ public class ShopUpdate extends OptionsActivity { HttpURLConnection conn = null; InputStream is = null; String contentAsString = ""; - + URL url = null; try { - URL url = params[0]; + url = params[0]; conn = (HttpURLConnection) url.openConnection(); conn.setReadTimeout(10000 /* milliseconds */); conn.setConnectTimeout(15000 /* milliseconds */); @@ -115,19 +116,17 @@ public class ShopUpdate extends OptionsActivity { contentAsString = contentAsString + reader.nextLine(); } } catch (MalformedURLException e) { - e.printStackTrace(); + Log.e("ShopUpdate", "The API doesn't respond correctly. Asked url was " + url.toString(), e); } catch (ProtocolException e) { - e.printStackTrace(); + Log.e("ShopUpdate", "The protocol doesn't seems to be HTTP. Url was " + url.toString(), e); } catch (IOException e) { - e.printStackTrace(); + Log.e("ShopUpdate", "The API response is not readable. Url was " + url.toString(), e); } finally { // Makes sure that the InputStream is closed after the app is finished using it. if (is != null) try { is.close(); - } catch (IOException e) { - e.printStackTrace(); - } + } catch (IOException e) {} if (conn != null) conn.disconnect(); } diff --git a/Les Horaires/src/main/java/com/amine/horaires/util/Parseur.java b/Les Horaires/src/main/java/com/amine/horaires/util/Parseur.java index 3cdd4f2..21ab2e9 100644 --- a/Les Horaires/src/main/java/com/amine/horaires/util/Parseur.java +++ b/Les Horaires/src/main/java/com/amine/horaires/util/Parseur.java @@ -1,17 +1,16 @@ package com.amine.horaires.util; +import android.util.Log; import com.amine.horaires.models.Shop; import org.xml.sax.Attributes; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; +import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; +import java.io.*; import java.util.ArrayList; /** @@ -215,8 +214,12 @@ public class Parseur { saxParser.parse(is, handler); - } catch (Exception e) { - e.printStackTrace(); + } catch (ParserConfigurationException e) { + Log.wtf("Parseur", "The parser configuration seems to be unexpected.", e); + } catch (IOException e) { + Log.e("Parseur", "API response seems to be unexpected.", e); + } catch (SAXException e) { + Log.e("Parseur", "Impossible to parse API response.", e); } return listeMagasins; diff --git a/Les Horaires/src/main/java/com/amine/horaires/util/Utils.java b/Les Horaires/src/main/java/com/amine/horaires/util/Utils.java index fb2de9f..5855140 100644 --- a/Les Horaires/src/main/java/com/amine/horaires/util/Utils.java +++ b/Les Horaires/src/main/java/com/amine/horaires/util/Utils.java @@ -1,5 +1,7 @@ package com.amine.horaires.util; +import android.util.Log; + import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import java.net.URL; @@ -13,10 +15,10 @@ public class Utils { + "&get=shops" + "&loc=" + URLEncoder.encode(location, "ISO-8859-1") + "&name=" + URLEncoder.encode(name, "ISO-8859-1")); } catch (MalformedURLException e) { - e.printStackTrace(); + Log.e("Utils", "URL was malformed.", e); return null; } catch (UnsupportedEncodingException e) { - e.printStackTrace(); + Log.e("Utils", "Fail to encode the URL", e); return null; } } @@ -30,10 +32,10 @@ public class Utils { + "&get=shops" + "&lng=" + lng + "&lat=" + lat + "&name=" + URLEncoder.encode(name, "ISO-8859-1") + "&order=distance"); } catch (MalformedURLException e) { - e.printStackTrace(); + Log.e("Utils", "URL was malformed.", e); return null; } catch (UnsupportedEncodingException e) { - e.printStackTrace(); + Log.e("Utils", "Fail to encode the URL", e); return null; } } @@ -45,7 +47,7 @@ public class Utils { + Configuration.key + "&h=" + Configuration.hashtag + "&get=shop" + "&id=" + idPoi); } catch (MalformedURLException e) { - e.printStackTrace(); + Log.e("Utils", "URL was malformed.", e); return null; } } @@ -57,7 +59,7 @@ public class Utils { + Configuration.key + "&h=" + Configuration.hashtag + "&get=edit" + "&id=" + idPoi + periodsString); } catch (MalformedURLException e) { - e.printStackTrace(); + Log.e ("Utils", "URL was malformed.", e); return null; } }