aspose file tools
The moose likes Java in General and the fly likes Hide a URL: Example (Download THIS File) Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Hide a URL: Example (Download THIS File)" Watch "Hide a URL: Example (Download THIS File)" New topic
Author

Hide a URL: Example (Download THIS File)

Hend Hamad
Greenhorn

Joined: Mar 08, 2009
Posts: 5
Hello,

I'm currently developing a chat application and it offers file exchange. To make things easier for me I developed a simple FTP connection using Java’s URL Connection:
URLConnection urlc = url.openConnection();
InputStream is = urlc.getInputStream(); // To download
OutputStream os = urlc.getOutputStream(); // To upload

Now I want to hide the link or URL from the participants of the conversation; when a file is uploaded the link will be posted on the chat pane, and when clicked a download window will open (Similar to MSN messenger). I want to hide the link, any ideas on how to do it??
Brian Legg
Ranch Hand

Joined: Nov 07, 2008
Posts: 488
link.hide()

Kidding, but tagged because I need to find out the exact same thing for my customer as well.


SCJA
~Currently preparing for SCJP6
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3268

Hend Hamad wrote:Hello,

I'm currently developing a chat application and it offers file exchange. To make things easier for me I developed a simple FTP connection using Java’s URL Connection:
URLConnection urlc = url.openConnection();
InputStream is = urlc.getInputStream(); // To download
OutputStream os = urlc.getOutputStream(); // To upload

Now I want to hide the link or URL from the participants of the conversation; when a file is uploaded the link will be posted on the chat pane, and when clicked a download window will open (Similar to MSN messenger). I want to hide the link, any ideas on how to do it??


Have you thought about using Apache's FTP library or JSCH's SFTP library?

Also I assume by hiding the link you don't want to show:

http ://someserver:8080/file1.txt


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16480
    
    2

Before we can tell you how to hide the link, we need to know how you are displaying the link in the first place. Is this a Swing application? A web application? Something else?
Hend Hamad
Greenhorn

Joined: Mar 08, 2009
Posts: 5
Have you thought about using Apache's FTP library or JSCH's SFTP library?


Not Really .. I'll have to google them

Before we can tell you how to hide the link, we need to know how you are displaying the link in the first place. Is this a Swing application? A web application? Something else?


The link is sent in this format: ftp ://address:port/filename (optionally the path), and it is displayed in a swing application (Text Area) as a String so far.

I've been playing around with HTTP (http instead of ftp), I was able to download files from the webserver (Apache Tomcat). Hoewever; the upload seems to be much trickier and I couldn't find a way to do it!!

So I guess that I will continue using ftp ..
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 3026
    
    4

Are you using a TextArea or a JTextArea? I hope a JTextArea...

Consider using a Highlighter to act as a 'link' like you would get in HTML. The highlight will be used to mark specific text in the JTextArea. When you get a URL to the FTP download, parse out the file name, add that to the JTextArea. Create a Highlighter to the position of the word in the text that has a custom HighlightPainter to paint the 'link' text anyway you want. Then take the returned Object (usually a JLabel I think) and add a MouseListener that will begin the download when clicked.
JTextComponent#getHighlighter()
Highlighter
HighlightPainter

Steve
Hend Hamad
Greenhorn

Joined: Mar 08, 2009
Posts: 5
Are you using a TextArea or a JTextArea? I hope a JTextArea...


I'm using JTextArea .. the 'J' was left out accidently

Consider using a Highlighter to act as a 'link' like you would get in HTML.


I will try your way .. I think it might just work .. Thanks
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Hide a URL: Example (Download THIS File)
 
Similar Threads
Hide the whole URL from the User
Exception while opening a Remote file.
How to provide download option on href link?
File Uploads - how to make uploaded file available for download
Display values form database