Read contents of file into outputstream and send through socket

I have a file. Instead of transferring the whole file through socket to the destination, I will read the contents from the file (big or small file size) into outputstream and send them to the destination where the client will receive the data and directly display it....
Can you suggest any efficient way/methods to achieve that?
Thanks.

I don' t understand what you think the difference is between those two techniques, but:
int count;
byte[] buffer = new byte[16384];
while ((count = in.read(buffer)) > 0)
  out.write(buffer, 0, count);
out.close();
in.close();

Similar Messages

  • Read contents of file into outputstream

    Can anyone suggest that what are the best methods to read contents of a file (better cater to both conditions: big file size and small file size) into outputstream and send through socket...
    Thanks.

    Thanks for the answer. But I would like to ask the following question:
    I have a VB application which generates a file. I have a Java application which read the contents of the file.
    is it possible that VB side calls the read() (file) and send() (through socket to destination) methods in Java application once the file is generated? Actually my objective is VB is responsible for generating a file for Java application to read data from and then send the data (not file) to destination....If it is impossible to achieve, any alternative to achieve this?
    Thanks
    Edited by: whkhoo on Jun 15, 2008 8:45 PM

  • How to convert smartform into pdf and send through mail

    Hi Guru,
    I want to send smartform to mail after converting into pdf format.
    if anyof u gives solution its greate.
    Thanks & Regards,
    Lakshmi..

    Hi,
    i can help you till
    downloading the smartform as pdf format
    check this
    DATA: GIT_BSIK LIKE BSIK OCCURS 0 WITH HEADER LINE.
    Variable declarations
    DATA:
    W_FORM_NAME TYPE TDSFNAME VALUE 'ZFII_EDD001',
    W_FMODULE TYPE RS38L_FNAM,
    W_CPARAM TYPE SSFCTRLOP,
    W_OUTOPTIONS TYPE SSFCOMPOP,
    W_BIN_FILESIZE TYPE I, " Binary File Size
    W_FILE_NAME TYPE STRING,
    W_FILE_PATH TYPE STRING,
    W_FULL_PATH TYPE STRING.
    Internal tables declaration
    Internal table to hold the OTF data
    DATA:
    T_OTF TYPE ITCOO OCCURS 0 WITH HEADER LINE,
    Internal table to hold OTF data recd from the SMARTFORM
    T_OTF_FROM_FM TYPE SSFCRESCL,
    Internal table to hold the data from the FM CONVERT_OTF
    T_PDF_TAB LIKE TLINE OCCURS 0 WITH HEADER LINE.
    This function module call is used to retrieve the name of the Function
    module generated when the SMARTFORM is activated
        CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
        EXPORTING
        FORMNAME = W_FORM_NAME
        VARIANT = ' '
        DIRECT_CALL = ' '
        IMPORTING
        FM_NAME = W_FMODULE
        EXCEPTIONS
        NO_FORM = 1
        NO_FUNCTION_MODULE = 2
        OTHERS = 3
        IF SY-SUBRC <> 0.
          MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
          WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        ENDIF.
    Calling the SMARTFORM using the function module retrieved above
    GET_OTF parameter in the CONTROL_PARAMETERS is set to get the OTF
    format of the output
    W_CPARAM-NO_DIALOG = 'X'.
    W_CPARAM-PREVIEW = SPACE. " Suppressing the dialog box
    " for print preview
    W_CPARAM-GETOTF = 'X'.
    Printer name to be used is provided in the export parameter
    OUTPUT_OPTIONS
    W_OUTOPTIONS-TDDEST = 'ZPC_'.
          CALL FUNCTION W_FMODULE
          EXPORTING
          ARCHIVE_INDEX =
          ARCHIVE_INDEX_TAB =
          ARCHIVE_PARAMETERS =
          CONTROL_PARAMETERS = W_CPARAM
          MAIL_APPL_OBJ =
          MAIL_RECIPIENT =
          MAIL_SENDER =
          OUTPUT_OPTIONS = W_OUTOPTIONS
          USER_SETTINGS = 'X'
          IMPORTING
          DOCUMENT_OUTPUT_INFO =
          JOB_OUTPUT_INFO = T_OTF_FROM_FM
          JOB_OUTPUT_OPTIONS =
               TABLES
                ITAB                       = GIT_BSIK
          EXCEPTIONS
          FORMATTING_ERROR = 1
          INTERNAL_ERROR = 2
          SEND_ERROR = 3
          USER_CANCELED = 4
          OTHERS = 5.
          IF SY-SUBRC <> 0.
            MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          ENDIF.
    T_OTF[] = T_OTF_FROM_FM-OTFDATA[].
    Function Module CONVERT_OTF is used to convert the OTF format to PDF
          CALL FUNCTION 'CONVERT_OTF'
          EXPORTING
          FORMAT = 'PDF'
          MAX_LINEWIDTH = 132
          ARCHIVE_INDEX = ' '
          COPYNUMBER = 0
          ASCII_BIDI_VIS2LOG = ' '
          PDF_DELETE_OTFTAB = ' '
          IMPORTING
          BIN_FILESIZE = W_BIN_FILESIZE
          BIN_FILE =
          TABLES
          OTF = T_OTF
          LINES = T_PDF_TAB
          EXCEPTIONS
          ERR_MAX_LINEWIDTH = 1
          ERR_FORMAT = 2
          ERR_CONV_NOT_POSSIBLE = 3
          ERR_BAD_OTF = 4
          OTHERS = 5
          IF SY-SUBRC <> 0.
            MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          ENDIF.
    *To display File SAVE dialog window
    CALL METHOD cl_gui_frontend_services=>file_save_dialog
    EXPORTING
    WINDOW_TITLE =
    DEFAULT_EXTENSION =
    DEFAULT_FILE_NAME =
    FILE_FILTER =
    INITIAL_DIRECTORY =
    WITH_ENCODING =
    PROMPT_ON_OVERWRITE = 'X'
    CHANGING
    filename = w_FILE_NAME
    path = w_FILE_PATH
    fullpath = w_FULL_PATH
    USER_ACTION =
    FILE_ENCODING =
    EXCEPTIONS
    CNTL_ERROR = 1
    ERROR_NO_GUI = 2
    NOT_SUPPORTED_BY_GUI = 3
    others = 4
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    Use the FM GUI_DOWNLOAD to download the generated PDF file onto the
    presentation server
    CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
    BIN_FILESIZE = W_bin_filesize
    filename = w_FULL_PATH
    FILETYPE = 'BIN'
    APPEND = ' '
    WRITE_FIELD_SEPARATOR = ' '
    HEADER = '00'
    TRUNC_TRAILING_BLANKS = ' '
    WRITE_LF = 'X'
    COL_SELECT = ' '
    COL_SELECT_MASK = ' '
    DAT_MODE = ' '
    CONFIRM_OVERWRITE = ' '
    NO_AUTH_CHECK = ' '
    CODEPAGE = ' '
    IGNORE_CERR = ABAP_TRUE
    REPLACEMENT = '#'
    WRITE_BOM = ' '
    TRUNC_TRAILING_BLANKS_EOL = 'X'
    WK1_N_FORMAT = ' '
    WK1_N_SIZE = ' '
    WK1_T_FORMAT = ' '
    WK1_T_SIZE = ' '
    IMPORTING
    FILELENGTH =
    tables
    data_tab = T_pdf_tab
    FIELDNAMES =
    EXCEPTIONS
    FILE_WRITE_ERROR = 1
    NO_BATCH = 2
    GUI_REFUSE_FILETRANSFER = 3
    INVALID_TYPE = 4
    NO_AUTHORITY = 5
    UNKNOWN_ERROR = 6
    HEADER_NOT_ALLOWED = 7
    SEPARATOR_NOT_ALLOWED = 8
    FILESIZE_NOT_ALLOWED = 9
    HEADER_TOO_LONG = 10
    DP_ERROR_CREATE = 11
    DP_ERROR_SEND = 12
    DP_ERROR_WRITE = 13
    UNKNOWN_DP_ERROR = 14
    ACCESS_DENIED = 15
    DP_OUT_OF_MEMORY = 16
    DISK_FULL = 17
    DP_TIMEOUT = 18
    FILE_NOT_FOUND = 19
    DATAPROVIDER_EXCEPTION = 20
    CONTROL_FLUSH_ERROR = 21
    OTHERS = 22
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    thanks & regards,
    Venkatesh

  • Sender File (FCC) - Content of File into single XML Tag

    Hi,
    Input file
    This is Line1
    This is Line2
    Expected Sender File adapter FCC into XML
    <Document>
    .<File>
    ..<Content> This is line 1 This is line2</content>
    .</File>
    </Document>
    FCC is giving the following output with the below config,
    File.fieldNames = Content
    File.fieldSeparator = '0x1A' (HexaDecimal rep for EndOfFile)
    <Document>
    .<File>
    ..<Content>This is line 1</content>
    ..<Content>This is line 2</content>
    .</File>
    </Document>
    How can i read the complete file into a single XML tag?
    I am aware of other options (AdapterModules or Javamapping). But i want to keep it simple to FileAdapter using FCC or using MessageTransformBean (if possible)
    -SM

    FCC donse't work here, So i wrote a simple Java map inside Execute method to convert the content to the required format.
      public void execute(InputStream in, OutputStream out)  throws StreamTransformationException{
    StringBuilder sb = new StringBuilder();
           try {
           BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
           while ((line = reader.readLine()) != null) {
               sb.append(line).append("\r\n");
           } finally {
           in.close();
    After i had the input string, i formatted it to get the required output as XML ...
    <Document>
    .<File>
    ..<Content> This is line 1 This is line2</content>
    .</File>
    </Document>

  • Open and read from text file into a text box for Windows Store

    I wish to open and read from a text file into a text box in C# for the Windows Store using VS Express 2012 for Windows 8.
    Can anyone point me to sample code and tutorials specifically for Windows Store using C#.
    Is it possible to add a Text file in Windows Store. This option only seems to be available in Visual C#.
    Thanks
    Wendel

    This is a simple sample for Read/Load Text file from IsolateStorage and Read file from InstalledLocation (this folder only can be read)
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Windows.Storage;
    using System.IO;
    namespace TextFileDemo
    public class TextFileHelper
    async public static Task<bool> SaveTextFileToIsolateStorageAsync(string filename, string data)
    byte[] fileBytes = System.Text.Encoding.UTF8.GetBytes(data);
    StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
    var file = await local.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting);
    try
    using (var s = await file.OpenStreamForWriteAsync())
    s.Write(fileBytes, 0, fileBytes.Length);
    return true;
    catch
    return false;
    async public static Task<string> LoadTextFileFormIsolateStorageAsync(string filename)
    StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
    string returnvalue = string.Empty;
    try
    var file = await local.OpenStreamForReadAsync(filename);
    using (StreamReader streamReader = new StreamReader(file))
    returnvalue = streamReader.ReadToEnd();
    catch (Exception ex)
    // do somthing when exception
    return returnvalue;
    async public static Task<string> LoadTextFileFormInstalledLocationAsync(string filename)
    StorageFolder local = Windows.ApplicationModel.Package.Current.InstalledLocation;
    string returnvalue = string.Empty;
    try
    var file = await local.OpenStreamForReadAsync(filename);
    using (StreamReader streamReader = new StreamReader(file))
    returnvalue = streamReader.ReadToEnd();
    catch (Exception ex)
    // do somthing when exception
    return returnvalue;
    show how to use it as below
    async private void Button_Click(object sender, RoutedEventArgs e)
    string txt =await TextFileHelper.LoadTextFileFormInstalledLocationAsync("TextFile1.txt");
    Debug.WriteLine(txt);
    在現實生活中,你和誰在一起的確很重要,甚至能改變你的成長軌跡,決定你的人生成敗。 和什麼樣的人在一起,就會有什麼樣的人生。 和勤奮的人在一起,你不會懶惰; 和積極的人在一起,你不會消沈; 與智者同行,你會不同凡響; 與高人為伍,你能登上巔峰。

  • Read an XML file into an ABAP program and manipulate it.

    I would like to know if it is possible to do the following in an ABAP program:
    1) Read an XML file into an ABAP internal table
    2) Call an XSLT transformation on the source file and store the results in an ABAP table.
    Is this possible to do? I have used ABAP XSLT in PI, but never in an ABAP program. I see you can use the CALL TRANSFORMATION command, but I have never used it in an ABAP program.
    Kind Regards,
    Tony.

    Check out these blogs.
    XML DOM Processing in ABAP part I -  Convert an ABAP table into XML file using SAP DOM Approach.
    XML DOM Processing in ABAP part II - Convert an XML file into an ABAP table using SAP DOM Approach.

  • When I save a CS6 InDesign file as an .idml file InDesign crashes and sends a report to Adobe.

    When I save a CS6 InDesign file as an .idml file InDesign crashes and sends a report to Adobe.
    When I restart InDesign the .idml file is in the directory as well as a locked InDesign file.
    I cannot open the .idml file, instead I get the message:
    Cannot open "" file. Adobe InDesign maynot support the file format,
    a plug-in that supports the file format may be missing,
    or the file may be open in another location.
    I can however open an InDesign .idml file that was saved from InDesign CC software.
    InDesign CC software is also unable to open the .idml file that I created in CS6.

    It seems to be a corrupted IDML file. Does it happen with every file or only with that one.
    What is the content of that file? Did you embed images or graphics or did you ink them? Size?
    Maybe that this would help you: Re: InDesign 6 is crashing when attempting to open a particular document. All others are opening OK.

  • Uploading the contents of file into  custom table

    Hi ,
    I have a req where in i want to put the contents of the file into the Z table . I have taken a file upload UI element and in that i have taken 4 attributes as file name f, file type ,file size and file contents and binded this file contents to the data property of the UI element. Now with out explicitly defining the fields i want to put all this content of file into the Z table created  for any file created or if i could put the whole text file into that table so that any one could see that file even though its not saved in the desktop for that user.
    Can any one help me out?

    Yes i am converting it inot the lstring using the same FM which you have given. I have to store the total file but the only doubt is like if its a input field how could i save a file form. Can you please check the code i want to save the total file into the table.
    DATA lo_nd_upload TYPE REF TO if_wd_context_node.
        DATA lo_el_upload TYPE REF TO if_wd_context_element.
        data  i_data TYPE STANDARD TABLE OF string.
        DATA ls_upload TYPE wd_this->Element_upload.
        data lv_field type string.
        data lt_file type TABLE OF ZFILE_UPLOAD.
        data ls_file LIKE LINE OF lt_file.
        data l_xstring type xstring.
       data  fields TYPE string_table.
    data l_String type string.
      navigate from <CONTEXT> to <UPLOAD> via lead selection
        lo_nd_upload = wd_context->get_child_node( name = wd_this->wdctx_upload ).
      @TODO handle non existant child
      IF lo_nd_upload IS INITIAL.
      ENDIF.
      get element via lead selection
        lo_el_upload = lo_nd_upload->get_element( ).
      @TODO handle not set lead selection
        IF lo_el_upload IS INITIAL.
        ENDIF.
      get all declared attributes
        lo_el_upload->get_static_attributes(
          IMPORTING
            static_attributes = ls_upload ).
       DATA lv_file_contents TYPE wd_this->Element_upload-file_contents.
    navigate from <CONTEXT> to <UPLOAD> via lead selection
    @TODO handle non existant child
    IF lo_nd_upload IS INITIAL.
    ENDIF.
    get element via lead selection
       lo_el_upload = lo_nd_upload->get_element( ).
    alternative access  via index
    lo_el_upload = lo_nd_upload->get_element( index = 1 ).
    @TODO handle not set lead selection
       IF lo_el_upload IS INITIAL.
       ENDIF.
    get single attribute
       lo_el_upload->get_attribute(
         EXPORTING
           name =  'FILE_CONTENTS'
         IMPORTING
           value = l_xstring ).
    for text file conversion we have to FM
    CALL FUNCTION 'HR_KR_XSTRING_TO_STRING'
      EXPORTING
      FROM_CODEPAGE       = '8500'
        IN_XSTRING          = l_xstring
      OUT_LEN             =
    IMPORTING
       OUT_STRING          = l_string.
    SPLIT l_string  AT cl_abap_char_utilities=>newline INTO TABLE i_data.
      LOOP AT i_data INTO l_string.
        SPLIT l_string AT cl_abap_char_utilities=>horizontal_tab INTO TABLE fields.
        read TABLE fields into lv_field index 1.
    endloop.
    ls_upload will contain all the file details
    ls_file-file_size = xstrlen( ls_upload-file_contents ) * lv_float  .
    ls_file-file_name = ls_upload-file_name.
    ls_file-file_type = ls_upload-file_type.
    ls_file-file_contents = ls_upload-file_contents.
    insert ZFILE_UPLOAD FROM ls_file.
    thanks

  • My mac is converting Word and Excel files into Pages and Numbers files when I click to open them (or download and open them) from an email. I do I get this to stop? It's really aggravating.

    My mac is converting Word and Excel files into Pages and Numbers files when I click to open them from an email. Downloading them and opening them doesn't help. How do I make this stop? I don't use iLife and don't want to; my clients are using Office and it's easier for me, except when I have to copy and paste everything they send me from an iLife file back to Word and Excel. Help!!! It's like Apple has become Microsoft, forcing us to use their apps.

    Do you have Word & Excel installed, if yes, navigate in the finder to an example of each, right click and select 'Get Info' scroll down to 'Open With' and select the appropriate program, check the box that says 'Change All'

  • Is there a way to save a fillable form (in Reader) as a static (uneditiable) image and send it for signature without the recipient being able to revise the fields at all?

    Is there a way to save a fillable form (in Reader) as a static (uneditiable) image and send it for signature without the recipient being able to revise the fields at all? I have designed a number of fillable forms and sent them to our clients as Reader extended pdfs to be filled out and sent back. Now, certain clients want to be able to fill in the fields and save the doc as a pdf that can't be tampered with so that they can send it to their own people for signature to be returned to them hand-signed and scanned via email.
    Since the forms have been secured, and my cleints are only using the free Acrobat Reader, how can they save the filled in form as a static pdf to send on for signature? They do not want to have to print, scan and email. Is there an app, plug-in, simple solution to this?
    Thank you,
    Rumor

    The signature WILL work! I've just looked into it more, thank you so much for pointing me in that direction.
    I get it now, it locks the form fields in place after my coworker fills them in and signs it (as the very last step).
    I wish I would have asked on here a full day ago. Would have saved a lot of headache and Googling.
    Thanks again.

  • How to create xml file from Oracle and sending the same xml file to an url

    How to create xml file from Oracle and sending the same xml file to an url

    SQL/XML (XMLElement, XMLForest, XMLAgg, etc) and UTL_HTTP.
    Whether that works for you with the version of Oracle you have, your requirements, and needs is another story. A little detail goes a long way.

  • Attaching HTML file and sending through mail

    Hi
    My Requirement is
    I want to attach HTML File and send through mail id's.
    But there are number of html files
    user can select any  one file.
    it has to attach and send to the mail id.

    Hi V,
    check the link:
    http://wiki.sdn.sap.com/wiki/display/Snippets/SendEmailwithHTMLattachment.

  • Want to pull data from MDM into SAP and send it to portal.

    Hi,
    I have a requirement where-in i want to get some data from master data management application(a third party application) into sap and send that data to portal. Kindly suggest me on how to go about doing the same. Awaiting your kind responses guys.
    Regards
    Shailendra.k

    Hi Shailendra,
    Your requirement is a huge activity with multiple tasks which can be done in multiple ways.
    Some basic points:
    1. You can read data from your Third party application using
    a. Native SQL or
    b. a middleware as PI or
    c. using connectors based on the platform of the Third party application (VB, .NET, etc.)
    2. Data can be sent to portal using
    a. Middleware as PI or
    b. Creating RFC's
    c. BAPI's.
    For any specific details, you can check SDN as detailed posts on each of the above is available or can post further.
    Regards,
    Pranav.

  • I am trying to import quicktime audio files into FCPX and it's saying they're not suppored - Help?

    I am trying to import quicktime audio files into FCPX and it's saying they're not suppored … Help?

    Here is the How to import in itunes 11. Including the Join tracks option.
    http://support.apple.com/kb/PH12278
    Also if you have imported them then  this article gives a good understanding of how to tag these songs
    http://samsoft.org.uk/iTunes/audiobooks.asp
    the other option would be to use an App like Audiobook Builder to stitch the tracks together in upto 12 hour long sections and sends to itunes automatically. It is available in the App Store. There are others available, Audiobook binder is free

  • Reading a flat file into Oracle

    Can someone tell me the best way to read a flat file into Oracle8i?

    You can use SQL*Loader
    or programmatically with UTL_FILE package.
    (Please see documentation of SQL*Loader
    and using predefine package UTL_FILE)

Maybe you are looking for

  • 2010 Mac Pro boot 10.8.5 with 2nd drive?

    I have a 2010 Mac Pro at work and I'd like to match the OS and ProTools setup that I have at home (MBP with OS 10.8.5 and ProTools 10/11). The Mac Pro is currently OS 10.7.4 and I'm using ProTools 9. OS 10.7.4 doesn't support ProTools 10/11. Is it po

  • File Browse is emptied after failed validation

    Why does the file browse text box get emptied after a failed validation? Is there any way to prevent this? To further explain, create a form on a page with two page items, a text box and a file browse item, then put a not null validation on the text

  • This is ridiculous.  Cant play purchased songs.

    OK...I know that I am not the only one having this problem as it is all over the place.  Why will Apple not provide any support on this? Windows XP, purchased album from Itunes, cant play 2 songs off the album.  I get the "this computer is not author

  • How to transfer pdf's into Keynote?

    Having recently bought an ipad with keynote I am trying to sort out how to convert Pdf files into Keynote. The pdf page size is formatted to the ipad screen size already. Is it possible or do I have to buy Keynote for my Imac and import them as indiv

  • How do I pull object information out of a vector.

    I started in VB, and am now developing with java, so I'm finding small trip-ups which are to be expected. Anyways, I'm trying to get an object element from an object in a vector. I tried this, but it wouldn't return the "Name" query method: System.ou