How to send a 'filename' and a byte representation of a file

Hey
I have this very simpel program, the logic is.. Client sends a file to a server which stores the file... VERY SIMPEL!
But what i wanna do is to send the filename as well, so the server can name the file dynamically based on the source file received
My code looks like this now..
Server code
* To change this template, choose Tools | Templates
* and open the template in the editor.
package serverreceivefile;
import java.io.*;
import java.net.*;
* @author Maul
public class ServerReceiveFile {
     * @param args the command line arguments
    public static void main(String[] args) throws IOException {
        System.out.println("Server is starting../");
        //Create a server socket that listens for incoming connection
        //request on port 10000
        ServerSocket ss = new ServerSocket(10000);
        while(true){
         // Listen for incoming connection requests from client
         // programs, establish a connection, and return a Socket
         // object that represents this connection.
            Socket s = ss.accept();
            System.out.println("Accepting connection.../");
            // Start a thread to handle connection
            new ServerThread(s).start();
class ServerThread extends Thread{
    private Socket s;
    ServerThread(Socket s){
        this.s = s;
    @Override
    public void run(){
        BufferedInputStream bs = null;
        BufferedOutputStream bos = null;
        try {
          // Create an input stream reader that chains to the socket's
          // byte-oriented input stream. The input stream reader
          // converts bytes read from the socket to characters. The
          // conversion is based on the platform's default character
          // set.
          bs = new BufferedInputStream(s.getInputStream());
          bos = new BufferedOutputStream(new FileOutputStream("filecopy.txt"));
          int i = 0;
          while((i = bs.read()) != -1){
              bos.write(i);
          bs.close();
          bos.close();
          s.close();
          } catch (IOException ie){
        System.exit(0);
}Client code
* To change this template, choose Tools | Templates
* and open the template in the editor.
package serverclientsendfile;
import java.io.*;
import java.net.*;
* @author Maul
public class ServerClientSendFile {
     * @param args the command line arguments
    public static void main(String[] args) throws FileNotFoundException
        String host = "localhost";
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(
                "file.txt"));
        Socket s = null;
        try {
            s = new Socket(InetAddress.getByName(host), 10000);
            // Create an input stream reader that chains to the socket's
            // byte-oriented input stream. The input stream reader
            // converts bytes read from the socket to characters. The
            // conversion is based on the platform's default character
            // set.
            BufferedOutputStream bos = new BufferedOutputStream(s.getOutputStream());
            int c;
            while((c = bis.read()) != -1){
                bos.write(c);
            bis.close();
            bos.close();
        } catch (IOException ie){
}As you can see the server 'hard codes' the filename of the received file from the client..

Hi DJHingapus,
If you don't want to build a dialog scenario between client and server, you may use a fixed length header which holds the name of the file to send. The stream will be composed with the header immediately followed by the binaries of the file.

Similar Messages

  • MQ to File: How to send a Filename from JMS Header (MQ) to a File Adapter

    Hello Experts,
    I have a flat file coming into PI via JMS adapter (MQ) and going out on a File adapter (NFS). We would like to keep the file name consistence throughout the transaction. While coming from MQ our sender is sending the filename in one of the MQ Headers (JMSCorrelationID). We are trying to figure out how to read the file name from the MQ header and send it to the file adapter. Please let us know any other suggestions.
    Thanks,
    Mayur

    Use this UDF code in MessageMapping.
    try
    DynamicConfiguration conf = (DynamicConfiguration)
    container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
    DynamicConfigurationKey KEY_JMSCorrID = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/JMS","DCJMSCorrelationID");
    DynamicConfigurationKey KEY_FILENAME = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
    conf.put(KEY_FILENAME, conf.get(KEY_JMSCorrID));
    catch(Exception e){}
    return a; //a is some input field.
    Enable ASMA on receiver File channel.
    Edited by: Praveen Gujjeti on Mar 17, 2010 9:23 AM

  • How to send a request and get a response through xml

    How to send a request and get a response through xml files?

    This is the code that works for me. Hope you find it useful.
         public static String sendHttpGetRequest(String endpoint, String requestParameters){
              String result = null;
              // Send a GET request to the servlet
              try{
                   // Send data
                   String urlStr = endpoint;
                   if (requestParameters != null && requestParameters.length () > 0){
                        urlStr += "?" + requestParameters;
                   URL url = new URL(urlStr);
                   HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                   conn.setRequestProperty("Accept", "application/xml");
                   // Get the response
                   BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                   StringBuffer sb = new StringBuffer();
                   String line;
                   while ((line = rd.readLine()) != null){
                        sb.append(line);
                   rd.close();
                   result = sb.toString();
              } catch (Exception e){
                   e.printStackTrace();
              return result;
         }

  • How to send automatic mail and put attache file on batch file ?

    how to send automatic mail and put attache file on batch file ?
    START MAILTO:[email protected]?SUBJECT=PHONE%CALL^&BODY=Testing

    Hi,
    Do you want to use a batch file to create new email message (including recipients, subject and email body) with attachments? If so, I'd recommend you post your question in the Scripting Guys forum for further assistance:
    https://social.technet.microsoft.com/Forums/scriptcenter/en-US/home?forum=ITCG
    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.
    Please feel free to let me know if I've misunderstood something.
    Regards,
    Steve Fan
    TechNet Community Support
    It's recommended to download and install
    Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office
    programs.
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • HOW TO SEND THE REPORTS AND  THROUGH XI TO NON -SAP SYSTEM

    Hi Experts,
                 I want to know how to send the reports and  smartform through xi to another system. All the post blogs are   just explaning only about the FILE-TO-FILE, FILE-TO-IDOCS scenarios only.

    Hi,
    XI is the middleware that to be used to transfer the data between various systems and even you could design the Business Processes with it.
    In R/3 the smartforms, are generally converted to PDF and then  have to send it across to Non SAP systems. Similarly you can convert the smartforms to pdf format and keep it on application server. XI will pick up that pdf and will send it to Non SAP system either as mail or as an attachments.
    ABAP reports are normally used to re-present the data. If you need to transfer this data across the Non SAP systems then you have the IDOCs to be generated, RFC or ABAP Proxy to integrate this data with Non SAP system.
    XI is not restricted only upto file to file or file to IDOC scenarios. It have enormous capabilities to involve various Business Processes as well integrate various SAP or Non SAP systems.
    If need anymore  specific details, please let us know.
    Thanks
    Swarup

  • HT201290 how fail send Airdrop Photos and Videos to and from OS X 10.10.2 and iOS 8.

    how fail send Airdrop Photos and Videos to and from OS X 10.10.2 and iOS 8.

    Airdrop Photos and Videos to and from OS X 10.10.2 and iOS 8.

  • How to run the report and show the output in excel file

    salam
    how to run the report and show the output in excel file,
    how to run the report and print the o/p via printer
    how to run the report and send the o/p via mail
    thank u all

    Hi,
    There are Parameters DESTTYPE, DESFORMAT and DESNAME. You can set these parameters to get as you want.
    1) Output in Excel File
         ADD_PARAMETER(PL_ID, 'DESTYPE', TEXT_PARAMETER, 'FILE');
         ADD_PARAMETER(PL_ID, 'DESFORMAT', TEXT_PARAMETER, 'DELIMITED');
         ADD_PARAMETER(PL_ID, 'DESNAME', TEXT_PARAMETER, '<file_name>.XLS');2) output to printer
         ADD_PARAMETER(PL_ID, 'DESTYPE', TEXT_PARAMETER, 'PRINTER');
         ADD_PARAMETER(PL_ID, 'DESNAME', TEXT_PARAMETER, '<printer_name>');3) Email - Have to configure SMTP and all. ( i didn't checked it)
         ADD_PARAMETER(PL_ID, 'DESTYPE', TEXT_PARAMETER, 'MAIL');
         ADD_PARAMETER(PL_ID, 'DESNAME', TEXT_PARAMETER, '<email_id>');Regards,
    Manu.
    If this answer is helpful or correct, please mark it. Thanks.

  • How to insert a shoutbox and a counter in a flash file with html code?

    How to insert a shoutbox and a counter in a flash file with
    html code?
    Code shout box
    <!-- BEGIN MYSHOUTBOX.COM CODE -->
    <iframe src="
    http://489676.myshoutbox.com/"
    width="152" height="300" frameborder="0"
    allowTransparency="true"></iframe>
    <!-- END MYSHOUTBOX.COM CODE-->
    Code compteur
    <script type="text/javascript" src="
    http://www.123compteur.com/counterskinable01.php?votre_id=268303"></script><noscript><a
    href="
    http://www.123compteur.com"
    target="_blank">compteur</a></noscript>

    thx =D

  • How do I access classes and methods defined in a wsdl file

    I have been provided a wsdl file I need to find out how do I access classes and methods defined in a wsdl file directly instead of doing a wsdl2java...

    Several comments :
    1- is there any reason to have blank chars inserted after the path ? Seems that you already have a problem there. If possible, try to solve the problem at the source
    2- the end of line char is usually CR (Carriage Return, aka ASCII char 13 = $0D = Control-D). But LF (Line Feed = 10 = $0A = control-A) is also used (platform dependent). In LV, you can use the "Concatenate strings" function to add/insert control chars (found in the String Control Palette). However, this will not solve your problem of unwanted added blank chars at the end of your string.
    3- you can use the Trim white space.vi (in the "Additionnal string functions" sub-palette) to remove ALL the spaces in your string
    4- you can build your own "end space remover" function. :
    reverse the string, wire to a "Match pattern" function, use " +" (space + "+") to search for any number of spaces, reverse again the "after substring".
    5- there is no point 5 :-)
    You may find interesting description of ASCII chars here
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        

  • For preparing the filenames and paths for the oracle database files..

    Hi,
    I am preparing the filenames and paths for the oracle database files.....but I am not able to complete this one...Will you Please help for filling this one.
    Controlfile ---- > select name from v$controlfile;
    Redologfile -- > select member from v$logfile;
    Datafile --------- > select tablespace_name,file_name from dba_data_files order by 1;
    Tempfile --------> select tablespace_name,file_name from dba_temp_files;
    Spfile -----------> show parameter spfile
    Pfile --------------->
    Passwordfile ---->
    tnsnames.ora -->
    listener.ora------>
    sqlnet.ora ------>
    oratab ------------->
    Thanks
    Shiju

    orashiju wrote:
    Hi,
    I am preparing the filenames and paths for the oracle database files.....but I am not able to complete this one...Will you Please help for filling this one.
    Controlfile ---- > select name from v$controlfile;
    Redologfile -- > select member from v$logfile;
    Datafile --------- > select tablespace_name,file_name from dba_data_files order by 1;
    Tempfile --------> select tablespace_name,file_name from dba_temp_files;
    Spfile -----------> show parameter spfile
    Pfile --------------->spfile and pfile are located under $ORACLE_HOME/dbs/
    Passwordfile ----> passwordfile is located under $ORACLE_HOME/dbs
    tnsnames.ora -->
    listener.ora------>
    sqlnet.ora ------>all above files are under $ORACLE_HOME/network/admin
    oratab ------------->depends on operating system. Usualy under /etc/oratab

  • How could i parse string and link its model with my files in eclipse project?

    How could i parse string and link its model with my files in eclipse project?, as i read that we dont have to use standalone mode while working with eclipse projects.
    Example of what i want to do:
    I have file1.dsl in my project which contains some statements but the declaration of these statements are not in another file, i need to put them only in my code

    Hi Stefan,
    I have eclipse project contains 2 files, file1.dsl and file2.dsl, you can see the contents of the files below.
    file1.dsl contains some statements as shown below and file2.dsl contains the declarations of the variables. (like in C++ or Java we have declarations and usage)
    At this step file1.dsl and file2.dsl will be parsed successfully without any errors.
    Lets imagine that we will delete this project and will create another one and the new project will contain only file1.dsl (which contains the usage)
    At this step this file (file1.dsl) will contains some errors after parsing it, because we are using variables without declarations.
    So what i need is to parse the content of file2.dsl directly without adding this file to the project.
    I need to add the content of file2.dsl directly as a string in the code and parse it. just like that ( "int a;int b;" )
    And link file1.dsl with the model generated after parsing my string
    file1.dsl
    a++;
    b++;
    file2.dsl
    int a;
    int b;
    Thanks

  • How to retrieve the path and the name of the destination file in a link annotation

    Hi,
    In C++:
    How to retrieve the path and the name of the destination file in a link annotation and a Launch action.
    Sample of my code:
    //Determine if the annotation is a Link annotation
    if (PDAnnotGetSubtype(annot) == ASAtomFromString("Link")) {
    //Determine if the action is a Launch action
    if (PDActionGetSubtype(action) == ASAtomFromString("Launch")) {
    // What is the method ?
    Regards
    David G

    In general, get the annotation as a Cos object and examine it, in
    accordance with the PDF Reference.
    Aandi Inston

  • How to know the filename and extension of a file in PKCS7  envelope

    Hi! I've a programm that makes a PKCS7 file. I'm enveloping just one file at a time. I want to know if there is a way to know the filename and extension of the file INSIDE de PKCS7 envelope. Because I receive a file that has .p7 extension, but the real document, the one to be decyprted, I don't know its name nor its extension, and I need both for writing it (I will not just invent some name).
    Best regards!

    The construct of the PKCS7 structure you have, is defined in rfc2633. The part defining EncapsulatedContent is introduced in CMS [rfc2639], where no such attribute for a file name is saved in the structure.
    In some occasions, when it is critical, organizations add own object identifier and attibutes to save such descrptivie information as filename and extension.
    A practical approach is, on the signing side, sign the file A.ext to A-ext.p7m resp. A-ext.p7s
    You can not assume a global approach to get back the original filename (if you have no agreement on not the signing peer as above) of the encapsulated data. The reason is, the encapsulated data field is general and it does not neccesarily mean it was a file (a part of a stream or any definite sequence of bytes in general).

  • In Applet  how to send an ' image' and 'string' as parameter

    Hi,
    In web application, how to use post method in applet to send an ' image' and 'string' as a parameter, I can able to send the image alone form applet to servlet.

    869665 wrote:
    Hi,
    In web application, how to use post method in applet to send an ' image' and 'string' as a parameter, I can able to send the image alone form applet to servlet.One way to do this is to convert your binary image data to base64 (convert it to plain text) and send it along with your other String parameter, delimited with a & of course.
    Edited by: maheshguruswamy on Aug 2, 2011 11:59 AM

  • How to put Module filename and use current filename in code ?

    Hi,
    I was create SequenceCall (in MainSequence), but need to put Module filename and existing file where to find module. I found some old function that are not part of API anymore (TS_SequenceCallModuleSetUseCurrentFile() and TS_SequenceCallModuleSetSequenceName(). Those exists in help file, but not in tsapicvi.c.
    Can you someone help with this (CVI code) ?
    Best regards,
    branar
    Solved!
    Go to Solution.

    Hi,
    I create seq file in CVI code (based on excell file). So, all sequences and subsequences are generated by CVI code and Ecxell file. Currently, want to add SequenceCall in MainSequence. It work with:
    tsErrChkMsgPopup( TS_EngineGetSeqFileEx (EngineHandle, &errorInfo, SeqTemplate_path, TS_GetSeqFile_DoNotRunLoadCallback, TS_ConflictHandler_Prompt, &SequenceFileHandle));
    error= TS_SeqFileGetSequenceByName (SequenceFileHandle, NULL, "MainSequence", &SequenceHandle);
    tsErrChkMsgPopup( TS_SequenceGetNumSteps(SequenceHandle, &errorInfo, TS_StepGroup_Main, &iNumofSteps));
    tsErrChkMsgPopup( TS_EngineNewStep (EngineHandle, &errorInfo, "", "SequenceCall", &sequenceCallStep));
    tsErrChkMsgPopup( TS_StepSetName ( sequenceCallStep, NULL, szName));
    tsErrChkMsgPopup( TS_SequenceInsertStep ( SequenceHandle, &errorInfo, sequenceCallStep, iNumofSteps, TS_StepGroup_Main ));
    error= TS_StepGetModule ( sequenceCallStep, &errorInfo, &sequenceCallStepModule);
    Now, need to add Module name and sequence name to call. I was tried with some function, but those are not supported (at least in tsapicvi.c)
    error= TS_SequenceCallModuleSetUseCurrentFile ( sequenceCallStepModule, &errorInfo, VTRUE);
    error= TS_SequenceCallModuleSetSequenceName ( sequenceCallStepModule, &errorInfo, SeqTarget_path);
     Also, I not found similar function to use instead. Can you help me with this ?
    Best regards,
    branar

Maybe you are looking for