{"id":27064,"date":"2021-05-09T23:10:06","date_gmt":"2021-05-10T03:10:06","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/the-class-that-actually-gets-the-strings-over-the-network-by-means-of-an-objectinputstream-via-http-tunneling-programming-code-examples-java-j2ee-j2me-applets-and-basic-graphics\/"},"modified":"2021-05-09T23:10:06","modified_gmt":"2021-05-10T03:10:06","slug":"the-class-that-actually-gets-the-strings-over-the-network-by-means-of-an-objectinputstream-via-http-tunneling-programming-code-examples-java-j2ee-j2me-applets-and-basic-graphics","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=27064","title":{"rendered":"The class that actually gets the strings over the network by means of an ObjectInputStream via HTTP tunneling. #Programming Code Examples #Java\/J2EE\/J2ME #Applets and Basic Graphics"},"content":{"rendered":"<pre>\nimport java.net.*;\nimport java.io.*;\n\n\/** When this class is built, it returns a value\n *  immediately, but this value returns false for isDone\n *  and null for getQueries. Meanwhile, it starts a Thread\n *  to request an array of query strings from the server,\n *  reading them in one fell swoop by means of an\n *  ObjectInputStream. Once they've all arrived, they\n *  are placed in the location getQueries returns,\n *  and the isDone flag is switched to true.\n *  Used by the ShowQueries applet.\n *  <p>\n *  Taken from Core Web Programming Java 2 Edition\n *  from Prentice Hall and Sun Microsystems Press,\n  *  May be freely used or adapted.\n *\/\n\npublic class QueryCollection implements Runnable {\n  private String[] queries;\n  private String[] tempQueries;\n  private boolean isDone = false;\n  private URL dataURL;\n\n  public QueryCollection(String urlSuffix, URL currentPage) {\n    try {\n      \/\/ Only the URL suffix need be supplied, since\n      \/\/ the rest of the URL is derived from the current page.\n      String protocol = currentPage.getProtocol();\n      String host = currentPage.getHost();\n      int port = currentPage.getPort();\n      dataURL = new URL(protocol, host, port, urlSuffix);\n      Thread queryRetriever = new Thread(this);\n      queryRetriever.start();\n    } catch(MalformedURLException mfe) {\n      isDone = true;\n    }\n  }\n\n  public void run() {\n    try {\n      tempQueries = retrieveQueries();\n      queries = tempQueries;\n    } catch(IOException ioe) {\n      tempQueries = null;\n      queries = null;\n    }\n    isDone = true;\n  }\n\n  public String[] getQueries() {\n    return(queries);\n  }\n\n  public boolean isDone() {\n    return(isDone);\n  }\n\n  private String[] retrieveQueries() throws IOException {\n    URLConnection connection = dataURL.openConnection();\n    \/\/ Make sure browser doesn't cache this URL, since\n    \/\/ I want different queries for each request.\n    connection.setUseCaches(false);\n    \/\/ Use ObjectInputStream so I can read a String[]\n    \/\/ all at once.\n    ObjectInputStream in =\n      new ObjectInputStream(connection.getInputStream());\n    try {\n      \/\/ The return type of readObject is Object, so\n      \/\/ I need a typecast to the actual type.\n      String[] queryStrings = (String[])in.readObject();\n      return(queryStrings);\n    } catch(ClassNotFoundException cnfe) {\n      return(null);\n    }\n  }\n}\n<\/p><\/pre>\n<p>Note: Brought from our old site: http:\/\/www.salearningschool.com\/example_codes\/ on Jan 2nd, 2017 From: http:\/\/sitestree.com\/?p=10264<br \/> Categories:Programming Code Examples, Java\/J2EE\/J2ME, Applets and Basic Graphics<br \/>Tags:Java\/J2EE\/J2MEApplets and Basic Graphics<br \/> Post Data:2017-01-02 16:04:28<\/p>\n<p>\t\tShop Online: <a href='https:\/\/www.ShopForSoul.com\/' target='new' rel=\"noopener\">https:\/\/www.ShopForSoul.com\/<\/a><br \/>\n\t\t(Big Data, Cloud, Security, Machine Learning): Courses: <a href='http:\/\/Training.SitesTree.com' target='new' rel=\"noopener\"> http:\/\/Training.SitesTree.com<\/a><br \/>\n\t\tIn Bengali: <a href='http:\/\/Bangla.SaLearningSchool.com' target='new' rel=\"noopener\">http:\/\/Bangla.SaLearningSchool.com<\/a><br \/>\n\t\t<a href='http:\/\/SitesTree.com' target='new' rel=\"noopener\">http:\/\/SitesTree.com<\/a><br \/>\n\t\t8112223 Canada Inc.\/JustEtc: <a href='http:\/\/JustEtc.net' target='new' rel=\"noopener\">http:\/\/JustEtc.net (Software\/Web\/Mobile\/Big-Data\/Machine Learning) <\/a><br \/>\n\t\tShop Online: <a href='https:\/\/www.ShopForSoul.com'> https:\/\/www.ShopForSoul.com\/<\/a><br \/>\n\t\tMedium: <a href='https:\/\/medium.com\/@SayedAhmedCanada' target='new' rel=\"noopener\"> https:\/\/medium.com\/@SayedAhmedCanada <\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>import java.net.*; import java.io.*; \/** When this class is built, it returns a value * immediately, but this value returns false for isDone * and null for getQueries. Meanwhile, it starts a Thread * to request an array of query strings from the server, * reading them in one fell swoop by means of an &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=27064\">Continue reading<\/a><\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1917],"tags":[],"class_list":["post-27064","post","type-post","status-publish","format-standard","hentry","category-fromsitestree-com","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":10425,"url":"http:\/\/bangla.sitestree.com\/?p=10425","url_meta":{"origin":27064,"position":0},"title":"The class that actually gets the strings over the network by means of an ObjectInputStream via HTTP tunneling.","author":"","date":"August 28, 2015","format":false,"excerpt":"import java.net.*; import java.io.*; \/** When this class is built, it returns a value \u00a0*\u00a0 immediately, but this value returns false for isDone \u00a0*\u00a0 and null for getQueries. Meanwhile, it starts a Thread \u00a0*\u00a0 to request an array of query strings from the server, \u00a0*\u00a0 reading them in one fell\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10339,"url":"http:\/\/bangla.sitestree.com\/?p=10339","url_meta":{"origin":27064,"position":1},"title":"A Frame that lets you draw circles with mouse clicks","author":"","date":"August 26, 2015","format":false,"excerpt":"SavedFrame.java **************** A Frame that lets you draw circles with mouse clicks \/\/************** import java.awt.*; import java.awt.event.*; import java.io.*; \/** A Frame that lets you draw circles with mouse clicks \u00a0*\u00a0 and then save the Frame and all circles to disk. \u00a0* public class SavedFrame extends CloseableFrame \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 implements ActionListener\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":27016,"url":"http:\/\/bangla.sitestree.com\/?p=27016","url_meta":{"origin":27064,"position":2},"title":"A Frame that lets you draw circles with mouse clicks #Programming Code Examples #Java\/J2EE\/J2ME #AWT Components","author":"Author-Check- Article-or-Video","date":"May 8, 2021","format":false,"excerpt":"SavedFrame.java **************** A Frame that lets you draw circles with mouse clicks \/\/************** import java.awt.*; import java.awt.event.*; import java.io.*; \/** A Frame that lets you draw circles with mouse clicks * and then save the Frame and all circles to disk. * public class SavedFrame extends CloseableFrame implements ActionListener {\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":24457,"url":"http:\/\/bangla.sitestree.com\/?p=24457","url_meta":{"origin":27064,"position":3},"title":"Implement your Own Permission: Pretty Simple Java Code #Root","author":"Author-Check- Article-or-Video","date":"April 10, 2021","format":false,"excerpt":"Implementing Your Own Permission package com.gamedev.games; import java.io.*; import java.security.*; import java.util.Hashtable; import com.scoredev.scores.*; public class ExampleGame { public static void main(String args[]) throws Exception { HighScore hs = new HighScore(\"ExampleGame\"); if (args.length == 0) usage(); if (args[0].equals(\"set\")) { hs.setHighScore(Integer.parseInt(args[1])); } else if (args[0].equals(\"get\")) { System.out.println(\"score = \"+ hs.getHighScore()); }\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10467,"url":"http:\/\/bangla.sitestree.com\/?p=10467","url_meta":{"origin":27064,"position":4},"title":"FilterTag.java Custom tag that modifies the tag body","author":"","date":"August 28, 2015","format":false,"excerpt":"FilterTag.java Custom tag that modifies the tag body package cwp.tags; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; import java.io.*; import cwp.*; \/** A tag that replaces <, >, \", and & with their HTML \u00a0*\u00a0 character entities (<, >, \", and &). \u00a0*\u00a0 After filtering, arbitrary strings can be placed \u00a0*\u00a0 in either\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":27192,"url":"http:\/\/bangla.sitestree.com\/?p=27192","url_meta":{"origin":27064,"position":5},"title":"JTable Examples #Programming Code Examples #Java\/J2EE\/J2ME #Advanced Swing","author":"Author-Check- Article-or-Video","date":"May 13, 2021","format":false,"excerpt":"# JTableSimpleExample.java Simple table that takes column names and data from arrays of Strings. import java.awt.*; import javax.swing.*; \/** Simple JTable example that uses a String array for the * table header and table data. * *\/ public class JTableSimpleExample extends JFrame { public static void main(String[] args) { new\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/27064","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=27064"}],"version-history":[{"count":0,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/27064\/revisions"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=27064"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=27064"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=27064"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}