About Applet....

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sukatoa
    Contributor
    • Nov 2007
    • 539

    About Applet....

    Is it possible to communicate the online database from my applet without any conditions? or limitations?

    Conditions - a restricted combination of characters that might be suspected as a
    pattern of a virus that should be blocked...Secur ity concerns

    Limitations- Not all characters in ascii are welcome in an online database...

    It's just a weird idea...

    Im currently experimenting a simple hashcode generator in an applet...(uniqu e patterns)
    Then i would like to save it in the database,

    Is there any possibilities that might change the real code(generated code) as im transfering a copy of a hashcode to an online database?

    Any reply would be greatly appreciated...

    sukatoa.
  • BigDaddyLH
    Recognized Expert Top Contributor
    • Dec 2007
    • 1216

    #2
    Originally posted by sukatoa
    Is it possible to communicate the online database from my applet without any conditions? or limitations?

    Conditions - a restricted combination of characters that might be suspected as a
    pattern of a virus that should be blocked...Secur ity concerns

    Limitations- Not all characters in ascii are welcome in an online database...

    It's just a weird idea...

    Im currently experimenting a simple hashcode generator in an applet...(uniqu e patterns)
    Then i would like to save it in the database,

    Is there any possibilities that might change the real code(generated code) as im transfering a copy of a hashcode to an online database?

    Any reply would be greatly appreciated...

    sukatoa.
    I'm not a big fan of applets, but the best practice is to write your application in three layers:

    1. applet
    2. Middle layer on server
    3. Database

    Your applet doesn't communicate directly with the database. Evidence is that no java.sql classes appear in the applet class, nor in any code that gets downloaded with the applet class.

    Your applet communicates with a server component and that component communicates with the database.

    You may want to reconsider using an applet and write this as a web application.

    Comment

    • sukatoa
      Contributor
      • Nov 2007
      • 539

      #3
      Originally posted by BigDaddyLH
      I'm not a big fan of applets, but the best practice is to write your application in three layers:

      1. applet
      2. Middle layer on server
      3. Database

      Your applet doesn't communicate directly with the database. Evidence is that no java.sql classes appear in the applet class, nor in any code that gets downloaded with the applet class.

      Your applet communicates with a server component and that component communicates with the database.

      You may want to reconsider using an applet and write this as a web application.
      Yah, i forgot to mension about the server...

      so, can i assure that whatever combination of text i will be send to the server, it does not change the pattern until it saves on the database?

      Sukatoa...

      Comment

      • BigDaddyLH
        Recognized Expert Top Contributor
        • Dec 2007
        • 1216

        #4
        Originally posted by sukatoa
        Yah, i forgot to mension about the server...

        so, can i assure that whatever combination of text i will be send to the server, it does not change the pattern until it saves on the database?

        Sukatoa...
        Do you have something specific in mind when you ask this? I'm not sure what you are trying to say.

        Comment

        • sukatoa
          Contributor
          • Nov 2007
          • 539

          #5
          Originally posted by BigDaddyLH
          Do you have something specific in mind when you ask this? I'm not sure what you are trying to say.
          Im not pretty sure about the security exceptions in the cyberspace...

          All i want is to generate a unique combination of characters and save it in a file for experiments....

          Then after that, proceed to online database....

          My question is, is the file i have generated would be stored 100% in the online database? Without changing its pattern?

          For example, i have this,

          *^($#7 )(*!@#@+___7654 4(new line transparent)
          *&^%$!@%%$#() *& *&^%$

          When i just open this in a textpad, the new line '\n' replaced with a rectangular box stands vertically....s aved...

          and when i open that file again from my applet, the pattern changed...

          I get stucked in the middle of the experiment....

          That was not so specific, but i think you can now understand this...

          I will think again about this....

          Thanks for the reply bigDaddy....

          Comment

          • BigDaddyLH
            Recognized Expert Top Contributor
            • Dec 2007
            • 1216

            #6
            Your questions keep shifting, but I believe your question now is: I can't seem to write "\n" to a file correctly. Is that correct? Post the code that is in error.

            Comment

            • sukatoa
              Contributor
              • Nov 2007
              • 539

              #7
              Originally posted by BigDaddyLH
              Your questions keep shifting, but I believe your question now is: I can't seem to write "\n" to a file correctly. Is that correct? Post the code that is in error.
              Code:
              public void SaveFile(String path){
                      FileOutputStream writes = null;
                      String text = new String(textArea1.getText());
                      try{
                          byte out[] = text.getBytes();
                          writes = new FileOutputStream(path);
                          writes.write(out);
                      } catch(Exception e){
                          JOptionPane.showMessageDialog(null, "UNABLE TO SAVE FILE!!", "FATAL ERROR 98773", JOptionPane.WARNING_MESSAGE);
                      } finally{
                          try{
                              if(!writes.equals(null)){ //Under tracing... But no problem...
                                  writes.close();
                              }
                          } catch(Exception e){
                              JOptionPane.showMessageDialog(null, "AN ERROR OCCURED WHILE CLOSING THE FILE!!", "FATAL ERROR 102", JOptionPane.WARNING_MESSAGE);
                          }
                      }
                  }
              The code above has problem...
              My source of text is the textArea... "Under experiment".... .

              After saving, try to view it in textpad... All newlines were replaced with rectangular box stands vertically... But when i open it again on my program, no problem... Maybe there is a difference of coding when it comes to newline...

              The rectangular box that i mean is in 7F hex or FF hex in ASCII....

              What can you suggest the way i write the text to file?

              What is the weakness?....

              Update me...

              Comment

              • BigDaddyLH
                Recognized Expert Top Contributor
                • Dec 2007
                • 1216

                #8
                Originally posted by sukatoa
                Code:
                public void SaveFile(String path){
                        FileOutputStream writes = null;
                        String text = new String(textArea1.getText());
                        try{
                            byte out[] = text.getBytes();
                            writes = new FileOutputStream(path);
                            writes.write(out);
                        } catch(Exception e){
                            JOptionPane.showMessageDialog(null, "UNABLE TO SAVE FILE!!", "FATAL ERROR 98773", JOptionPane.WARNING_MESSAGE);
                        } finally{
                            try{
                                if(!writes.equals(null)){ //Under tracing... But no problem...
                                    writes.close();
                                }
                            } catch(Exception e){
                                JOptionPane.showMessageDialog(null, "AN ERROR OCCURED WHILE CLOSING THE FILE!!", "FATAL ERROR 102", JOptionPane.WARNING_MESSAGE);
                            }
                        }
                    }
                The code above has problem...
                My source of text is the textArea... "Under experiment".... .

                After saving, try to view it in textpad... All newlines were replaced with rectangular box stands vertically... But when i open it again on my program, no problem... Maybe there is a difference of coding when it comes to newline...

                The rectangular box that i mean is in 7F hex or FF hex in ASCII....

                What can you suggest the way i write the text to file?

                What is the weakness?....

                Update me...
                There are several basic mistakes in your code. Here are the three biggest:
                1. (Aside) Why are you making an unnecessary copy of a String? Your code:

                [CODE=Java]String text = new String(textArea 1.getText());[/CODE]

                Can be written more simply as:

                [CODE=Java]String text = textArea1.getTe xt();[/CODE]

                2. You need to understand the difference between text and binary data. You shouldn't be writing out a byte array using FileOutputStrea m. Take the tutorial on I/O:

                This Java tutorial describes exceptions, basic input/output, concurrency, regular expressions, and the platform environment


                3. Text components like JTextArea already have a methods to simplify I/O: check the API for methods read and write:




                Demo:

                [CODE=Java]public static void writeFromTextCo mponent(File file, JTextComponent comp) throws IOException {
                FileWriter out = new FileWriter(file );
                try {
                comp.write(out) ;
                } finally {
                out.close();
                }
                }[/CODE]

                Comment

                • sukatoa
                  Contributor
                  • Nov 2007
                  • 539

                  #9
                  Originally posted by BigDaddyLH
                  There are several basic mistakes in your code. Here are the three biggest:
                  1. (Aside) Why are you making an unnecessary copy of a String? Your code:

                  [CODE=Java]String text = new String(textArea 1.getText());[/CODE]

                  Can be written more simply as:

                  [CODE=Java]String text = textArea1.getTe xt();[/CODE]

                  2. You need to understand the difference between text and binary data. You shouldn't be writing out a byte array using FileOutputStrea m. Take the tutorial on I/O:

                  This Java tutorial describes exceptions, basic input/output, concurrency, regular expressions, and the platform environment


                  3. Text components like JTextArea already have a methods to simplify I/O: check the API for methods read and write:




                  Demo:

                  [CODE=Java]public static void writeFromTextCo mponent(File file, JTextComponent comp) throws IOException {
                  FileWriter out = new FileWriter(file );
                  try {
                  comp.write(out) ;
                  } finally {
                  out.close();
                  }
                  }[/CODE]
                  Roger....

                  About the string, don't worry, the JVM will change the byte code for it to optimize automatically.. ..

                  And, it was not finalized... I forgot it.... sorry....

                  So, here is my new problem...

                  How safe is this code?

                  Code:
                  private void CopyFile(File source){
                          try{
                          FileWriter copy = new FileWriter(new File("TEMP.COM"));
                          FileReader view = new FileReader(source);
                          int node = 0;
                          
                          while((node = view.read()) != -1){
                              copy.write(node);
                          }
                          copy.close();
                          view.close();
                          }catch(Exception e){e.printStackTrace();} // for debugging
                      }
                  I've used it to transfer the .COM file to the original path....
                  Is this code has a quality enough?

                  Or you have the best idea how to implement it?
                  how is your algo if you know it BigDaddy?!!

                  Update me.... ;-)

                  Comment

                  • BigDaddyLH
                    Recognized Expert Top Contributor
                    • Dec 2007
                    • 1216

                    #10
                    Originally posted by sukatoa
                    Roger....

                    About the string, don't worry, the JVM will change the byte code for it to optimize automatically.. ..

                    And, it was not finalized... I forgot it.... sorry....

                    So, here is my new problem...

                    How safe is this code?

                    Code:
                    private void CopyFile(File source){
                            try{
                            FileWriter copy = new FileWriter(new File("TEMP.COM"));
                            FileReader view = new FileReader(source);
                            int node = 0;
                            
                            while((node = view.read()) != -1){
                                copy.write(node);
                            }
                            copy.close();
                            view.close();
                            }catch(Exception e){e.printStackTrace();} // for debugging
                        }
                    I've used it to transfer the .COM file to the original path....
                    Is this code has a quality enough?

                    Or you have the best idea how to implement it?
                    how is your algo if you know it BigDaddy?!!

                    Update me.... ;-)
                    1. If an exception is thrown, you don't close either stream.
                    2. When you are copying text files, it may make more sense to do a binary copy and not copy as text. The exceptions to this include cases where you are chaning the charset encoding and when you are moving files between machines and are concerned about the difference in new-line characters between Windows and Linux, for example.

                    Comment

                    • sukatoa
                      Contributor
                      • Nov 2007
                      • 539

                      #11
                      Originally posted by BigDaddyLH
                      1. If an exception is thrown, you don't close either stream.
                      2. When you are copying text files, it may make more sense to do a binary copy and not copy as text. The exceptions to this include cases where you are chaning the charset encoding and when you are moving files between machines and are concerned about the difference in new-line characters between Windows and Linux, for example.
                      Code:
                      1. If an exception is thrown, you don't close either stream.
                      I forgot again....

                      Code:
                      The exceptions to this include cases where you are chaning the charset encoding and when you are moving files between machines and are concerned about the difference in new-line characters between Windows and Linux, for example.
                      This is what i've been waiting for BigDaddy....
                      You got the best answer that would convence me to make changes in my codes....

                      Maybe we have misunderstandin gs in the previous posts....

                      I am aware of it....

                      Thanks.... ;-)

                      Comment

                      Working...