Sending bytes of file

Hi,
We have an xml api that accepts order requests and returns xml responses based on the processing performed.
I would like to add a tag called <Lables> to the xml response that contains the contents (bytes?) of a pdf file generated on our side. I have the bytes[] array and am not sure how to send it in the response. I tried looping theough the byte array and appending the contents to the buffer, but it dumped the contents as integers..not sure if this is readable on the client side.
Please help..the code i have so far is shown below. I want he client side to be able to take the contents between the <Labels></Labels> tag and recreate the pdf file.
Thanks.
          try{
               File shippingLabels = new File(File.createTempFile("shippingLabel","").getAbsoluteFile() + ".pdf");                    
               BufferedOutputStream sbos = new BufferedOutputStream(new FileOutputStream(shippingLabels));
               carrierServiceManager.getShippingLabel(order, sbos);
               sbos.flush();
               sbos.close();
               InputStream is = new FileInputStream(shippingLabels);
               long length = shippingLabels.length();
               byte[] bytes = new byte[(int)length];
//               Read in the bytes
     int offset = 0;
     int numRead = 0;
     while (offset < bytes.length
     && (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
     offset += numRead;
     // Ensure all the bytes have been read in
     if (offset < bytes.length) {
     throw new IOException("Could not completely read file "+ shippingLabels.getName());
     is.close();
     builder.append("<Labels>");
     for(int i=0; i<bytes.length; i++)
          builder.append(bytes);
     builder.append("</Labels>\n");
          catch(Exception e){
               logger.error(e.getMessage());

DrClap is right. It would be more proper to send the PDF by some standard and descriptive format, which is the whole point of XML. However, many times it is not convenient to spend the resources to parse and reparse something like that when all you want to do is send it across byte-for-byte. In this case, I reccommend you send it as a hexadecimal string. It's much more efficient than sending it as a sequence of integers. In fact, hexadecimal is close to as small as you can get a binary file without compression into an XML file. Here's some code that returns a hexadecimal String given a java.io.InputStream of the binary data you want to serialize. /**
* The character array representing the hexadecimal characters to use for
* each digit
private static final char [] hexChars = new char [] {'0', '1', '2', '3',
     '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
* Translates a binary input stream into a hexadecimal String
* @param is The InputStream to translate
* @return A hexadecimal String that can be used to recreate <code>is</code>'s
*         data using the
*         {@link #translateBinaryStreamFrom(String, java.io.OutputStream)}
*         method
* @throws java.io.IOException If an I/O error occurs while reading from
*         <code>is</code>
public static String translateBinaryStream(java.io.InputStream is)
     throws java.io.IOException
     StringBuffer ret = new StringBuffer();
     int read = is.read();
     while(read >= 0)
          ret.append(hexChars[read >>> 4]);
     ret.append(hexChars[read & 0x0f]);
               read = is.read();
     return ret.toString();
}And here's the code to translate it back to a java.io.OutputStream/**
* @param hexChar The hexadecimal character in a hex String
* @return The hexadecimal digit <code>hexChar</code> encodes
* @throws java.lang.IllegalArgumentException If <code>hexChar</code> is
*         not a valid hexadecimal, i.e. if it is not in one of the ranges
*         ('0'...'9'), ('A'...'F'), ('a'...'f')
private static int getHexDigit(char hexChar)
     if(hexChar >= '0' && hexChar <= '9')
          return hexChar - '0';
     else if(hexChar >= 'A' && hexChar <= 'F')
          return hexChar - 'A' + 10;
     else if(hexChar >= 'a' && hexChar <= 'f')
          return hexChar - 'a' + 10;
     else
          throw new IllegalArgumentException("The input string is not in"
               + " hexadecimal format");
* Translates a hexadecimal String into binary data, writing it to an
* OutputStream
* @param hexString The hexadecimal String to translate
* @param os The OutputStream to write the binary data in
*        <code>hexString</code> to
* @throws java.io.IOException If an I/O error occurs while writing to
*         <code>os</code>
* @throws java.lang.IllegalArgumentException If any character in
*         <code>hexString</code> is not a valid hexadecimal, i.e. if it
*         is not in one of the ranges ('0'...'9'), ('A'...'F'), ('a'...'f')
public static void translateBinaryStreamFrom(String hexString,
     java.io.OutputStream os) throws java.io.IOException
     int dig;
     int out = 0;
     for(int i = 0; i < hexString.length(); i++)
          dig = getHexDigit(hexString.charAt(i));
          if(i % 2 == 0)
               out = dig << 4;
               if(i == hexString.length() - 1)
                    os.write(out);
          else
               out |= dig;
               os.write(out);
}This code is actually tested. Hope this helps.

Similar Messages

  • 0 byte txt file using receiver File Adapter

    HI,
    My scenario is Flat File to Fixed Length File.
    Mapping : Based on the condition Reciever node need to generated , In some cases it wont generate any node ( No data )
    Receiver Communication channel :  I used FCC for Fixed length Format.
    Problem : When i am generatingf the receiver file with some data it executes. But when i am generating the file with no data , it fails in the receiver comminication channel.
    Could not process due to error: java.lang.Exception: Exception in XML Parser (format problem?):'java.lang.Exception: Message processing failed in XML parser: 'Conversion configuration error: Unknown structure 'ns0:Message1' found in document', probably configuration error in file adapter (XML parser error)'
    I need the receiver file to generate with 0 bytes when there is empty data.
    can any one help on this.
    Thanks

    Hi,
    >>Problem : When i am generatingf the receiver file with some data it executes. But when i am generating the file with no data , it fails in the receiver comminication channel.
    What happens in this case is, when you send a blank file to PI it processes but once it went to Receiver Adapter, it looks out for some fields because of the FCC settings. So it throws an error/exception because some fields are expected and it is not coming. Because of that you getting below exception.
    Secondly, Once you send data with few values or fields it will process in Receiver file adapter FCC and if there is some error it throws error. this is why you getting exception in moni, and other places.
    Regards
    Aashish Sinha

  • Sending a pdf-file

    I need to send a pdf-file from another application to another. Now I am transporting it in several char[] tables. The problem is some characters are missing when the other end receives the pdf-file.
    So I'm asking that can a pdf-file be transported in several char-tables? Is it possible in general? (I don't have a possibility to send a byte stream, so I need to use char-tables).

    You are probably loosing high-bits off of some of the bytes when you
    convert them to a char[] or they are overflowing. Same result, corrupted
    pdf data....
    I suggest that you used Base64 to encode the byte[] data of the file
    and decode it on the other end when you receive it. As I remember
    Base64 should only produce printable characters so sending the data
    through a char[] should work fine.
    Note that this will increase the size of the data some.
    For a class that does Base64 encoding and decoding see.
    org.apache.xerces.impl.dv.util.Base64
    The Apache license is quite permissive so you can probably just include
    this class in you program.

  • How to send a text file over a LAN?

    Hi:
    I am working on a program (web app using a servlet), that produces a text file with Key / Value pairs ex) NAME
    joe
    CITY
    los angeles
    I want to send the text file over an intranet (LAN) to another pc and store it in the C:\temp directory of the receiving computer.
    Is it best to use the Networking package? Any idea on tutorials or code samples to help assist me? (I posted on Servlet Technology forum; nobody answered though...thanks for any thoughts.

    one way cud be that u write a program to open a port on the computer u want to store and make that program save on the required directory. then u can send a simple file in byte format over it. but doing this only wud b unsafe as others wud also hav the access. wat u cud do to prevent is to put some kind of password so that first u authenticate to server b4 u pass on the file.
    bye
    jods

  • How to send a text file as jsp response

    Hi
    I want to send a text file/or other file as jsp response ..How to do it..
    Pls tell me if any body knows about it..
    thanks

    Hmmm im no expert but i think you would have to convert it to a byte array and use OutputStream with the response ... not sure ...like i said, im no expert

  • Send a picture file using sockets

    Hi,
    Could someone please tell me how I can send a picture file using sockets across a TCP/IP network? I have managed to do it by converting the file into a byte array and then sending it but I dont see the data back at the client when I recieve the file. I just see the byte array as having size 0 at client.
    Byte array size is correct at client side.
    //client code
    System.out.println("Authenticating client");
              localServer = InetAddress.getLocalHost();
              AuthConnection = new Socket(localServer,8189);
              out = new PrintWriter(AuthConnection.getOutputStream());
              InputStream is = AuthConnection.getInputStream();
              System.out.println(is.available());
              byte[] store = new byte[is.available()];
              is.read(store);
         ImageIcon image = new ImageIcon(store);
              JLabel background = new JLabel(image);
              background.setBounds(0, 0, image.getIconWidth(), image.getIconHeight());
              getLayeredPane().add(background, new Integer(Integer.MIN_VALUE));
    //extra code here
              catch (UnknownHostException e) {
    System.err.println("Don't know about host: LocalHost");
    System.exit(1);
              catch (IOException e) {
    System.err.println("Couldn't get I/O for "
    + "the connection to: LocalHost");
    System.exit(1);
    //server code
                   DataOutputStream out = new DataOutputStream(incoming.getOutputStream());
                   FileInputStream fin = new FileInputStream("3trees.gif");
                   byte[] b = new byte[fin.available()];
                   int ret = fin.read(b);
                   out.write(b);

    i used OutputStream as
    OutputStream out = incoming.getOutputStream(); and flushed the stream too.
    But I still get the same output on the client side. I tried sending a string and it works , but I cant seem to be able to populate the byte array on the client side. It keeps showing zero. Please advise.
    Thank you.

  • Sending an Image file to a client using UDP

    I wants to send an Image file from the client to the server using UDP. As UDP can only sends data of type byte, how can i convert the Image file to byte & send it. Here is the Client program:
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import java.awt.*;
    public class Client {
    public static void main(String[] args) throws IOException {
    if (args.length != 1) {
    System.out.println("Usage: java Client <hostname>");
    return;
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String str = br.readLine();
    br.close();
    // get a datagram socket
    DatagramSocket socket = new DatagramSocket();
    // send request
    byte[] buf = new byte[65500];
    buf = str1.getBytes();
    InetAddress address = InetAddress.getByName(args[0]);
    DatagramPacket packet = new DatagramPacket(buf, buf.length, address, 4445);
    socket.send(packet);
    // get response
    packet = new DatagramPacket(buf, buf.length);
    socket.receive(packet);
    // display response
    String received = new String(packet.getData());
    System.out.println("Received: " + received);
    socket.close();
    Thanx.

    DataInputStream inStream = new DataInputStream(new FileInputStream(filename));
    try {
    byte bindata = inStream.readByte();
    catch (EOFException eof) {
    }

  • How can i send a big file as pararameter of any method in a Web Service???

    Hello,
    i have a problem,,,,, i want to send a file of 2mb as parameter of a web service method.
    When i send this file as a vector of bytes i have the error out of memory...
    If the file is 200kb or smaller works fine....
    How can i send a big file as pararameter of any method in a Web Service???
    thanks in advance and excuse me for my bad english

    you can think about streams.
    in our case, what we did is, we will place a file in a common ftp server and return the url to the client.
    regards,
    mukunt

  • Detect "end of file" while send n numbers files over a socket?

    Hi!
    I�m trying to find a way to detect "end of file" while send n numbers files over a socket.
    What i'm looking for is how to detect on the client side when the file i�m sending is downloaded.
    Here is the example i�m working on.
    Client side.
    import java.io.*;
    import java.net.*;
    public class fileTransfer {
        private InputStream fromServer;
        public fileTransfer(String fileName) throws FileNotFoundException, IOException {
            Socket socket = new Socket("localhost", 2006);
            fromServer = socket.getInputStream();
            for(int i=0; i<10; i++)
                receive(new File(i+fileName));
        private void receive(File uploadedFile) throws FileNotFoundException, IOException {
            uploadedFile.createNewFile();
            FileOutputStream toFile = new FileOutputStream(uploadedFile);
            byte[] buffer = new byte[4096];
            int bytesRead = 0;
            while ((bytesRead = fromServer.read(buffer)) != -1) {
                toFile.write(buffer, 0, bytesRead);
        public static void main(String[] args) {
            try {
                new fileTransfer("testa.jpg");
            } catch (Exception ex) {ex.printStackTrace();}
    }Server side.
    import java.io.*;
    import java.net.*;
    public class fileTransferSend {
        Socket serv = null;
        OutputStream toClient;
        public fileTransferSend(String fileName) throws FileNotFoundException, IOException {
            StartServer();       
            for(int i =0; i<10; i++)
                send(new File(fileName));
        public void StartServer() throws IOException {
            ServerSocket ssocket = new ServerSocket(2006);
            System.out.println("Waiting for incomming");
            serv = ssocket.accept();
            System.out.println("incomming");
            toClient = serv.getOutputStream();
        private void send(File f) throws FileNotFoundException, IOException {
            if(f.exists() && f.canRead()) {
                FileInputStream fromFile = new FileInputStream(f);
                try {
                    byte[] buffer = new byte[4096]; // 4K
                    int bytesRead = 0;
                    System.out.println("sending: "+f.getName());
                    while ((bytesRead = fromFile.read(buffer)) != -1) {
                        toClient.flush();
                        toClient.write(buffer, 0, bytesRead);
                finally {
                    //toClient.close();
                    fromFile.close();
            } else {
                System.out.println("no files");
        public static void main(String[] args) {
            try {
                new fileTransferSend("test.jpg");
            }catch(Exception e) {e.printStackTrace();}
    I know that the client never reads -1 becuase i doesn�t close the stream.
    Is there anyway to tell the client that the file is downloaded?

    A common (and easy) TCP/IP protocol is to send length, followed by data.
    Because TCP/IP is a stream-oriented protocol, a receiver can never absolutely determine where the first packet ends and the second packet begins. So it is common to send the length of the packet, followed by the packet itself.
    In your case, you could send length of file, followed by file data. It should be fairly easy to obtain file length and send that as a 32-bit (or 64-bit value). Here is an idea (not code) for the receiver:
    receive (4) // where 4 = number bytes to receive
    unsigned length = convert 4 bytes to unsigned integer
    while (length != 0)
    n = receive ( length ) // where n = number bytes actually received, and length = number bytes desired
    Or, you can use the concept of an "Escape" character in the stream. Arbitrarily choose an ESCAPE character of 0x1B (although it could be any 8-bit value). When the receiver detects an ESCAPE char, the next character can be either control or data. So for end of file you might send 0x1B 0x00. If the byte to be sent is 0x1B, then send 0x1B 0x1B. The receiver would look something like this:
    b = read one byte from stream
    if (b == 0x1B)
    b = read one byte from stream
    if (b == 0x00) then end of file
    else place b in buffer
    else
    place b in buffer
    Later.

  • Problen when Sending the text file as attachment to the external mail

    HI,
    I am sending the text file as an attachment to a aexternal mai. mailing is going with text file attachment, but text file is empty. No information in the file is going, only empty text file is going. I am sending the code  iam using. Please suggest, if I need to change any passing parameters orany other other solution.
    tables: knb1,kna1,adr6,ITEMSET,bsid,TSP01.
               INTERNAL TABLES
    DATA: BEGIN OF it_kna1 occurs 0,
            KUNNR LIKE KNA1-KUNNR,
            ADRNR LIKE KNA1-ADRNR,
          END OF it_kna1.
    DATA: BEGIN OF it_email occurs 0,
            ADDRNUMBER LIKE ADR6-ADDRNUMBER,
            SMTP_ADDR LIKE ADR6-SMTP_ADDR,
          END OF it_email.
    DATA: BEGIN OF it_bsid occurs 0,
           KUNNR LIKE BSID-KUNNR,
           BUKRS LIKE BSID-BUKRS,
         END OF it_bsid.
    DATA: BEGIN OF it_final occurs 0,
            KUNNR LIKE KNA1-KUNNR,
            ADRNR LIKE ADR6-ADDRNUMBER,
            EMAIL LIKE ADR6-SMTP_ADDR,
          END OF it_final.
    DATA: BEGIN OF BUFFER OCCURS 10000,
              TEXT(255) TYPE C,
            END OF BUFFER.
    data:xtext type solix_tab." occurs 0 with header line."line.
    data:xi_pdf type soli_tab.
    DATA: OBJPACK LIKE SOPCKLSTI1 OCCURS 2  WITH HEADER LINE,
          OBJHEAD LIKE SOLISTI1   OCCURS 1  WITH HEADER LINE,
          OBJBIN  LIKE SOLISTI1   OCCURS 0  WITH HEADER LINE,
          OBJTXT  LIKE SOLISTI1   OCCURS 10 WITH HEADER LINE,
          RECLIST LIKE SOMLRECI1  OCCURS 5  WITH HEADER LINE,
          DOC_CHNG  LIKE SODOCCHGI1,
         PARAMS   LIKE PRI_PARAMS,
         ARPARAMS LIKE ARC_PARAMS,
         DAYS(1)  TYPE N VALUE 8,
         COUNT(3) TYPE N VALUE 1,
         VALID    TYPE C,
         RECEIVER(30),
         STR(256).
    data:  spoolid    type tsp01-rqident,
           pdf_table like tline occurs 0 with header line,
           v_bytecount type i,
           itab_pdf like tline occurs 10 with header line,
          xi_pdf  like tline occurs 0 with header line,
          xi_pdf  like buffer occurs 0 with header line,
           xi_pdf_1 like xi_pdf,
           v_length(2) type p,
           html  like solisti1   occurs 0  with header line,
           xi_temp      like bapiqcmime occurs 0 with header line,
           xi_mime(255) type c occurs 0 with header line.
              VARIABLES
    data: g_email type adr6-smtp_addr,
          TAB_LINES LIKE SY-TABIX,
          G_FLAG(1) TYPE C.
         g_norm(1) TYPE C,
         g_shbv(1) TYPE C,
         g_merk(1) TYPE C,
         g_park(1) TYPE C,
         g_apar(1) TYPE C.
    data: l_lines     type i,
          line1       type i,
          l_temp(500) type c,
          l_offset    type p,
          l_lineslen(2) type p,
          l_mimelen(2)  type p,
          v_spono like tsp01-rqident,
          l_tabix       like sy-tabix.
    *****VIA SELECTION-SCREEN
    ENDFORM.                    " SEND_TO_SPOOL
    *&      Form  GET_SPOOL_ID
    *&      Form  CONVERT_SPOOL_TO_PDF
    *&      Form  SEND_MAIL
    FORM SEND_MAIL .
      data:l_lin  like sy-tabix,
            l_lint like sy-tabix,
            it_list like abaplist occurs 0,
            l_newline(2) type x value '0D0A'.
    *--Data for the status output after sending
      data: user_address like sousradri1 occurs 1 with header line,
            sent_to_all like sonv-flag.
      clear: reclist, reclist[],
             objtxt , objtxt[],
             objpack, objpack[],
             objbin , objbin[],
             doc_chng.
    *--move list to office table objbin
    *--Start of Changes to support PDF attachments - UB20030116
    loop at html.
       objbin-line = html-line.
       append objbin.
       clear objbin.
    endloop.
    loop at xi_pdf.
       objbin-line = xi_pdf-text.
       append objbin.
       clear objbin.
    endloop.
    *--We may write additional text to the main document
    *--For faxing this will be the cover page. Like sending from SAPoffice
    *--the layout set Office-Telefax will be used.
      objtxt-line = 'NOTE : Please Consider the below Headers'.
      append objtxt.
      clear objtxt.
      objtxt-line = 'Assignment -->  Purchase order number '.
      append objtxt.
      clear objtxt.
      objtxt-line = 'Document  -->   Invoice No '.
      append objtxt.
      clear objtxt.
      objtxt-line = 'Amount In DC --> Amount Due '.
      append objtxt.
      clear objtxt.
      objtxt-line = '                                            '.
      append objtxt.
      clear objtxt.
      objtxt-line = '                                            '.
      append objtxt.
      clear objtxt.
      objtxt-line = 'Please find attached statement for this week'.
      append objtxt.
      clear objtxt.
      objtxt-line = '                                            '.
      append objtxt.
      clear objtxt.
      objtxt-line = 'This is an AUTO GENERATED MAIL'.
      concatenate objtxt-line 'Please Do not reply to this mail' into
      objtxt-line separated by ' '.
      append objtxt.
      clear objtxt.
      describe table objtxt lines tab_lines.
      read table objtxt index tab_lines.
    *--Create the document which is to be sent
    doc_chng-obj_name  = 'List'.
      doc_chng-obj_name = 'SAPRPT'.
    doc_chng-obj_descr = 'Customer statement for the week'.
      concatenate 'Customer statement for '
                  sy-datum into
                  doc_chng-obj_descr
                  separated by ' '.
      doc_chng-doc_size = ( tab_lines - 1 ) * 255 + strlen( objtxt ).
    *--Fill the fields of the packing_list for the main document:
    *--It is a text document
      clear objpack-transf_bin.
    *--The document needs no header (head_num = 0)
      objpack-head_start = 1.
      objpack-head_num = 0.
    *--but it has a body
      objpack-body_start = 1.
      objpack-body_num = tab_lines.
    *--of type RAW
      objpack-doc_type = 'RAW'.
      append objpack.
    *--Create the attachment (the list itself)
      describe table objbin lines tab_lines.
    *--Fill the fields of the packing_list for the attachment:
    *--It is binary document
    objpack-transf_bin = 'X'.
    *--we need no header
      objpack-head_start = 1.
      objpack-head_num = 0.
    *--but a body
      objpack-body_start = 1.
      objpack-body_num = tab_lines.
    *--of type G_DOC_TYPE
    objpack-doc_type = 'PDF'. "commented on 12/13/2007
      objpack-doc_type = 'TXT'. "commented on 12/13/2007
      objpack-obj_name = 'Attachment'.
    objpack-obj_descr = 'Customer Statement'.
      concatenate 'Customer Statement' sy-datum into objpack-obj_descr.
      objpack-doc_size = tab_lines * 255.
      append objpack.
      reclist-receiver = g_email.
      reclist-rec_type = 'U'.
    reclist-com_type = 'FAX'.
      append reclist.
      data:xi type soli.
    xi-line = 'haisdgsfsdf'.
    append xi to xi_pdf.
    xi-line = 'haisdfdsfd'.
    append xi to xi_pdf.
    xi-line = 'haisfgsdfsd'.
    append xi to xi_pdf.
    xi-line = 'haisdfsgfsdgg'.
    append xi to xi_pdf.
    *xi_pdf-text = 'hai'.
    *append xi_pdf.
    *xi_pdf-text = 'hai'.
    *append xi_pdf.
    *xi_pdf-text = 'hai'.
    *append xi_pdf.
    *xi_pdf-text = 'hai'.
    *append xi_pdf.
    CALL FUNCTION 'SO_SOLITAB_TO_SOLIXTAB'
        EXPORTING
          ip_solitab        = xi_pdf[]
       IMPORTING
         EP_SOLIXTAB       = xtext[].
    **--Send the document by calling the SAPoffice API1 module for sending
    **--documents with attachments
      call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
        EXPORTING
          document_data              = doc_chng
          PUT_IN_OUTBOX              = 'X'
         COMMIT_WORK                = 'X'
        IMPORTING
          sent_to_all                = sent_to_all
        TABLES
          packing_list               = objpack
          object_header              = objhead
         contents_bin               = objbin
          contents_txt               = objtxt
          contents_hex               = xtext
          receivers                  = reclist
        EXCEPTIONS
          too_many_receivers         = 1
          document_not_sent          = 2
          operation_no_authorization = 4
          others                     = 99.

    HI,
    There are lots of bugs.
    Please refer this sample program to fix it.
    http://www.sapdevelopment.co.uk/reporting/rep_spooltopdf.htm
    Best regards,
    Prashant

  • I have tried a lot to find an app or some way in email to attach multiple of pdf files in one email. I could not find anything that sends multiple pdf file in one email and still keeping the file in simple pdf format for the recipient.

    I have tried a lot to find an app or some way in email to attach multiple of pdf files in one email. I could not find anything that sends multiple pdf file in one email and still keeping the file in simple pdf format for the recipient.

    I am not aware of a way except for photos that allows you to select multiple files in an email. I even checked settings in the Adobe Reader app, and it does not show that ability.

  • Sending EMail "Text-File" from Application Server!

    Hi Experts,
    how can I sending a Text-File from Application Server via Email?
    Is there existing a Function Modul?
    With Kind regards
    Ersin
    Moderator message: sending emails = FAQ, please search before posting.
    Edited by: Thomas Zloch on Nov 25, 2010 4:23 PM

    STF (Search the forum)!  This type of question has been asked...and answered....many times.

  • How do I store an Int, a short, and multiple bytes from file in byte array

    I'm attempting to do this for a project but can't figure out how to store the three values in one byte array. This is what i've tried
    public void send(byte[] input)
              // TODO
              ByteArrayInputStream bais = new ByteArrayInputStream(input);
              ByteArrayOutputStream baos = new ByteArrayOutputStream();
              DataOutputStream dos = new DataOutputStream(baos);
              byte[] pData = new byte[100];
              try {
                   dos.writeShort(checkSum);
                   dos.writeInt(nextSeqNum);
                   pData=baos.toByteArray();
                   bais.read(pData);
              } catch (IOException e) {
              DatagramPacket dgp = new DatagramPacket(pData, pData.length);When i set pData=baos.toByteArray() it changes the size and then stops me from being able to read the other 94 bytes into the array to send. Any ideas?

    You don't need the ByteArrayInputStream at all.
    dos.writeShort(checkSum);
    dos.writeInt(nextSeqNum);
    dos.write(input);
    pData = baos.toByteArray();
    When i set pData=baos.toByteArray() it changes the sizeNo, it makes it refer to a new byte[] array containing what you've written to the BAOS. That's what it's supposed to do.

  • How do I change my email address when sending a PDF file:

    How do I change my email address (correct it) when sending a PDF file?

    You'll need to add the email address you want to use to Reader... If you're not prompted to do so when clicking the Submit button, you can do it via Edit - Preferences - Email Accounts.

  • I have Windows 7, Microsoft Outlook and PSE 13. I have used the "Share photos as embedded images" feature frequently, but today when I went to use it, it wasn't there, only the option to send email with files attached. How do I get back the ability to sen

    I have Windows 7, Microsoft Outlook and PSE 13. I have used the "Share photos as embedded images" feature frequently, but today when I went to use it, it wasn't there, only the option to send email with files attached. How do I get back the ability to send emails with photos embedded. I like adding the frames and backgrounds and I think it's easier for recipients to look at the photos. Thanks for any suggestions of things to try.
    Gail

    I had a similar problem in that my wife's iphone 5 could not send pics with imessage.  Had to set the settings to default to SMS or whatever.  After laboring many hours on the web I coincidentally was on the phone with the internet people to question my internet speed.  They changed the router channel, which is something that I am capable of doing myself.  After that, the pics go over imessage.  My own Iphone didn't have the problem.  We are both latest IOS 7.0.6.

Maybe you are looking for

  • Firefox no longer works for many Banks

    The whole point of Firefox was that it was customizable. Now it doesn't work. It doesn't even work on your own pages. I may as well use AppleSafari or switch to Chrome or Opera. I hate having to waste my time customizing Chrome, but will seriously co

  • Pictures screen saver.  My "best" photos look granular. Why?

    Hello. I have a number of photos saved on my mac. Some were taken years ago with a cheap digital camera. Some were scanned in recently using a scanner. Others were taken using a more expensive, good quality, slr camera. I refer to the slr pictures as

  • Why is my iTunes icon gone from my phone?

    Why is my Itunes icon gone from my phone. I don't have it anymore.

  • Critical error in VDI. host is unresponsive

    Dear all, i am facing problem here. i am clicking on Desktop provider in the left panel. on the right hand side, there is critical error saying: "Critical. The Desktop provider cannot serve any desktop. check hosts and storages" also in the top it is

  • PeopleSoft HRMS 9.1 Feature Pack Installation(thread 911549)

    PeopleSoft HRMS 9.1 Feature Pack Installation(thread 911549) I have successfully installed all the softwares of PeopleSoft HRMS: Upto step 7 http://geekswithblogs.net/BizTalkUnleashed/archive/2012/01/24/installing-peoplesoft-hrms-9.0-on-windows-serve