当前位置: 动力学知识库 > 问答 > 编程问答 >

inputstream - Java: Receive files of multiple types

问题描述:

I didn't see a similar question and I apologize if this question is not specific enough.

I will start out with that I am new to Java, I coded in it about 10+ years ago (basic stuff), but don't remember any of it. I am working on a program that listens on a socket and can receive multiple data types, I.E. Text, receive FTP file, receive http post file. I would like to be able analyze the incoming data type and then process each type differently. I have found several articles on how to do everything on separate ports, but wanted to find out if there is a better way to do so.

The problem I have with some of the solutions is that I don't want a full ftp or http server, I just want to receive files via ftp put or http post.

Edit: When I say I don't need a server, I mean I don't need to handle anything outside of receiving the file.

Additional Clarity: Take something simple like this(example purposes only)

BufferedReader br = null;

in = new BufferedReader(

new InputStreamReader(socket.getInputStream()));

while (true) {

String input;

while((input = br.readLine()) != null){

System.out.println(input);

}

in.close();

}

That will just print whatever text I send the listener. I'm wondering if there is a way to check the input stream for type. This might be beyond my skills, but would like someplace to read up on it. Everything I read is type(FTP, HTTP, custom client) specific, so ideally I would check the input stream and then do something.

if(socket.getInputStream() == HTTP || FTP){

//receive file

}

else if(stream == text){

//parse text

}

else { //unsupported format }

or

String streamType = getStreamType(inputStream) //returns input stream type.

Up til this point, my coding experience has all been what to do with data I get. This is my first time working with sockets and listeners.

Thanks

分享给朋友:
您可能感兴趣的文章:
随机阅读: