Missing bytes

hi! im trying to read a byte array sent by a local server to a local client but when i print the array read from the stream the array is missing two bytes. here is where the problem occurs. please help me.
Client side:
public void GetFrame(Socket connection, String funcframe){
     StringBuffer instr = new StringBuffer();                         
     int frame = 0, index = 0;
     boolean notempty = true;
     try {                                                       
          InputStream in = connection.getInputStream();
          OutputStream osw = connection.getOutputStream();                                        
          osw.write(SOSFRAME);
          osw.flush();
          int c;               
          frame = in.read();
          if (frame == SOSRESPFRAME){                    
               byte[] bytearray = new byte[funcframe.length()+1];                              
               bytearray[0] = (byte)GETFRAME;
               System.out.println("bytearray length" + funcframe.length()+1);
               for (index = 0; index < funcframe.length(); index++){
                    if (funcframe.charAt(index) != ',' && funcframe.charAt(index)!= (char) 13){
                         System.out.println(" char at funcframe "+ funcframe.charAt(index));                    
                         bytearray[index + 1] = ((byte)(Character.digit((funcframe.charAt(index)), 16)));
                         System.out.println(" inside loop = "+ bytearray[index + 1]);
               osw.write(bytearray);
               osw.flush();
               in.read(bytearray); // this is where the problem occurs
               for(index = 0; index < bytearray.length; index++) {
                    System.out.println("bytearray"+ (char)bytearray[index] +" "+bytearray.length);
               if(bytearray[0] == (byte)GETRESPFRAME){
                    instr.setLength(0);
                    do{                         
                         if (bytearray[1] != 0){
                              System.out.println("error in set frame");
                              System.exit(-1);
                         else {          
                              System.out.println("value for " + (int)bytearray[2]);                         
                              for(index = 0; index < (int)bytearray[2]+1; index++) {
                                   System.out.println((char)bytearray[index + 3]);
                                   if (bytearray[index + 3] != 0)
                                        instr.append((char)bytearray[index + 3]);
                              if (bytearray[(int)bytearray[2] + 3] == 0) {
                                   notempty = false;
                    }while(notempty);
               /*     instr.setLength(0);
                    for(index = 0; index < Array.getLength(bytearray)-1; index++) {
                         if (bytearray[index + 1] != 0)
                              instr.append((char)bytearray[index + 1]);
          else {
               System.out.println("start of session response not recieved");                    
               connection.close();
          save(instr);
     catch (IOException e)
          System.err.println ("IOException: " + e);
Server side:
if (bytearray[0] == (byte)GETFRAME){
    packet = "";
    System.out.println("in get frame");
       File file = new File ("C:\\Program Files\\Xinox Software\\JCreatorV3LE\\MyProjects\\frame.txt");                              
     bytearray[0] = (byte)GETRESPFRAME;
     byte[] filearray = new byte [getBytesFromFile(file).length];
     System.out.println("getBytesFromFile(file).length"+getBytesFromFile(file).length);
     filearray = getBytesFromFile(file);
     copyArray(filearray, bytearray, 1);
    out.write(bytearray); // this is where the bytes that i meant is being written
    for(index = 0; index < filearray.length + 1; index++) {
          System.out.println("## "+(char)bytearray[index]);
    out.flush();                                      
}          I really need help.. thanks.

in.read(bytearray); // this is where the problem occursIt sure is. This function returns an important value which you are ignoring.

Similar Messages

  • IOException: Missing byte-order mark

    Hi,
    I have an application which reads emails and processes them. It is currently getting an exception for two emails:-
    IOException: Missing byte-order mark
    As the application is in a production environment, I'm limited in the amount of debugging and tracing I can run to try to resolve this. Does anyone know what might be causing this and how it might be resolved so that these emails can be processed?
    Thanks in advance!

    The stack trace is:-
    INFO | jvm 1 | 2009/10/20 13:09:04 | sun.io.MalformedInputException: Missing byte-order mark
    INFO | jvm 1 | 2009/10/20 13:09:04 |      at sun.io.ByteToCharUnicode.convert(Unknown Source)
    INFO | jvm 1 | 2009/10/20 13:09:04 |      at sun.nio.cs.StreamDecoder$ConverterSD.convertInto(Unknown Source)
    INFO | jvm 1 | 2009/10/20 13:09:04 |      at sun.nio.cs.StreamDecoder$ConverterSD.implRead(Unknown Source)
    INFO | jvm 1 | 2009/10/20 13:09:04 |      at sun.nio.cs.StreamDecoder.read(Unknown Source)
    INFO | jvm 1 | 2009/10/20 13:09:04 |      at java.io.InputStreamReader.read(Unknown Source)
    INFO | jvm 1 | 2009/10/20 13:09:04 |      at com.sun.mail.handlers.text_plain.getContent(text_plain.java:99)
    INFO | jvm 1 | 2009/10/20 13:09:04 |      at javax.activation.DataSourceDataContentHandler.getContent(DataHandler.java:789)
    INFO | jvm 1 | 2009/10/20 13:09:04 |      at javax.activation.DataHandler.getContent(DataHandler.java:536)
    INFO | jvm 1 | 2009/10/20 13:09:04 |      at javax.mail.internet.MimeBodyPart.getContent(MimeBodyPart.java:629)
    INFO | jvm 1 | 2009/10/20 13:09:04 |      at com.intralogic.service.EmailListener.readMessage(EmailListener.java:393)
    INFO | jvm 1 | 2009/10/20 13:09:04 |      at com.intralogic.service.EmailListener.readMessage(EmailListener.java:405)
    INFO | jvm 1 | 2009/10/20 13:09:04 |      at com.intralogic.service.EmailListener.captureEmails(EmailListener.java:286)
    INFO | jvm 1 | 2009/10/20 13:09:04 |      at com.intralogic.service.EmailListener.run(EmailListener.java:164)
    INFO | jvm 1 | 2009/10/20 13:09:04 |      at com.intralogic.EmailCapture.start(EmailCapture.java:75)
    INFO | jvm 1 | 2009/10/20 13:09:04 |      at com.intralogic.EmailCapture.main(EmailCapture.java:43)
    INFO | jvm 1 | 2009/10/20 13:09:04 |      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    INFO | jvm 1 | 2009/10/20 13:09:04 |      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    INFO | jvm 1 | 2009/10/20 13:09:04 |      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    INFO | jvm 1 | 2009/10/20 13:09:04 |      at java.lang.reflect.Method.invoke(Unknown Source)
    INFO | jvm 1 | 2009/10/20 13:09:04 |      at org.tanukisoftware.wrapper.WrapperSimpleApp.run(WrapperSimpleApp.java:240)
    INFO | jvm 1 | 2009/10/20 13:09:04 |      at java.lang.Thread.run(Unknown Source)

  • ADF Faces : UploadedFile missing bytes

    hi
    Please consider a simple ADF Faces application, in JDeveloper 10.1.3.3.0, with an upload page containing this:
      <f:view>
        <afh:html>
          <afh:head title="uploadedFileIssue">
            <meta http-equiv="Content-Type"
                  content="text/html; charset=windows-1252"/>
          </afh:head>
          <afh:body>
            <af:form usesUpload="true">
              <af:panelPage title="uploadedFileIssue">
                <af:panelForm>
                  <f:facet name="footer">
                    <af:commandButton text="Upload"/>
                  </f:facet>
                  <af:inputFile label="file to upload"
                                valueChangeListener="#{backing_uploadedFileIssue.onInputFileValueChange}"/>
                </af:panelForm>
              </af:panelPage>
            </af:form>
          </afh:body>
        </afh:html>
      </f:view>The backing bean class looks like this:
    package adfuploadedfileissue.view.backing;
    import javax.faces.event.ValueChangeEvent;
    import oracle.adf.view.faces.model.UploadedFile;
    public class UploadedFileIssue
         public void onInputFileValueChange(ValueChangeEvent pValueChangeEvent)
              UploadedFile vUploadedFile = (UploadedFile)pValueChangeEvent.getNewValue();
              System.out.println("UploadedFileIssue.onInputFileValueChange()"
                   + " : getFilename() = " + vUploadedFile.getFilename()
                   + ", getLength() = " + vUploadedFile.getLength());
    }The web.xml file has been configured like this:
        <context-param>
            <param-name>oracle.adf.view.faces.UPLOAD_MAX_MEMORY</param-name>
            <param-value>5120000</param-value>
        </context-param>
        <context-param>
            <param-name>oracle.adf.view.faces.UPLOAD_MAX_DISK_SPACE</param-name>
            <param-value>102400000</param-value>
        </context-param>You can download the complete application here (check README.txt):
    http://verveja.footsteps.be/~verveja/files/oracle/ADFUploadedFileIssue-v0.01.zip
    If I run this application, and upload some files, I get this output:
    UploadedFileIssue.onInputFileValueChange() : getFilename() = ADF-DeveloperGuide-4GL-B25947_01.pdf, getLength() = 10445516
    UploadedFileIssue.onInputFileValueChange() : getFilename() = OC4J-ConfigurationAndAdministrationGuide-b28950.pdf, getLength() = 4434458
    UploadedFileIssue.onInputFileValueChange() : getFilename() = OC4J-DeploymentGuide-b28951.pdf, getLength() = 3117284
    UploadedFileIssue.onInputFileValueChange() : getFilename() = OC4J-DevelopersGuide-b28952.pdf, getLength() = 2420815I have used these files to upload in this application:
    "Application Development Framework Developer's Guide for Forms/4GL Developers" (size 10445518 bytes, in UploadedFile 10445516, so 2 bytes missing)
    http://download.oracle.com/docs/cd/B32110_01/web.1013/b25947.pdf
    "Containers for J2EE Configuration and Administration Guide" (size 4434460 bytes, in UploadedFile 4434458 bytes, so 2 bytes missing)
    http://download.oracle.com/docs/cd/B32110_01/web.1013/b28950.pdf
    "Containers for J2EE Deployment Guide" (size 3117285 bytes, in UploadedFile 3117284 bytes, so 1 byte missing)
    http://download.oracle.com/docs/cd/B32110_01/web.1013/b28951.pdf
    "Containers for J2EE Developer's Guide" (size 2420816 bytes, in UploadedFile 2420815 bytes, so 1 byte missing)
    http://download.oracle.com/docs/cd/B32110_01/web.1013/b28952.pdf
    question:
    Why are there bytes missing in the UploadedFile instances?
    note:
    This issue is narrowed down from the discussion in this forum thread:
    " about "Upload and download files from ADF into blob type colum." "
    about "Upload and download files from ADF into blob type colum."
    many thanks
    Jan Vervecken

    Thanks for your reply John.
    In the Re: ADF Faces file upload: losing bytes on PDF file you refer to, you write "I'm currently guessing something wrong in the DB with Intermedia, but not sure.".
    But, using the ADFUploadedFileIssue-v0.01.zip example application I posted in this forum thread, it is clear that something is already wrong in the UploadedFile implementation.
    Currently I only have bug 6774514 logged, but no solution yet.
    regards
    Jan

  • Get canvas.toDataURL('image/jpeg') and convert base64 encoding to java.sql.Blob

    Convert canvas.toDataURL('image/jpeg') to java.sql.Blob.
    I am using oracle adf so I am able to action a backing bean from javascript and pass in parameters as a map. I pass in the canvas.toDataURL('image/jpeg') which I then try to decode in my bean. Using BASE64Decoder and the converting the bytearray to a file I can see the image is corrupted as I can't open the file thus converting the bytearray to blob is also a waste.
    Has anyone any ideas on base64 encoding from canvas.toDataURL to file or Blob?

    Use Case:
    A jsf page that enables a user to take photos using the HTML5 canvas feature - interact with webcam -, take photos and upload to profile
    1. I have created the jsf page with the javascript below; this pops up as a dialog and works okay and onclick an upload image, triggers the snapImage javascript function below and sends the imgURL parameter to the serverside managedbean
    <!-- java script-->
    function snapImage(event){
                    var canvas = AdfPage.PAGE.findComponent('canvas');
                    AdfCustomEvent.queue(event.getSource(),"getCamImage",{imgURL:canvas.toDataURL('image/jpeg'),true);
                    event.cancel();
    <!-- bean -->
    public void getCamImage(ClientEvent ce){
    String url=(String)ce.getAttributes().get("imgURL");
    decodeBase64URLToBlob(url);
    private BlobDomain decodeBaseB4URLToBlob(String url64){
                    BASE64Decoder de=new BASE64Decoder();
                    byte[] bytes=de.decode(url64);
                    File file=new File("abc.jpg");
                    InputStream in = new ByteArrayInputStream(bytes);
                    BufferedImage bImageFromConvert = ImageIO.read(in);
                    in.close();
                    ImageIO.write(bImageFromConvert, "jpg", file);
                    return createBlobDomainFromFile(file);
    ----problem---
    Accessing the generated jpeg file shows the image is corrupted, probably missing bytes or encode/decoder issues.and the blob image after uploading to database is saved as a binary stream which ondownload doesnt render as an image or anything i know of.
    Is there anyways of achieving the conversion without errors?

  • PDF file on my view

    I want attach my PDF file on my web dynpro view
    I have read in this forum about my problem the using of IFrame element but don't work.
    Please help me, thanks

    I guess you could avoid such problems using mapping. Here's some example code, modified from an example:
    // Original code from 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002
    // www.BruceEckel.com. See copyright notice in CopyRight.txt.
    import java.io.RandomAccessFile;
    import java.nio.MappedByteBuffer;
    import java.nio.channels.FileChannel;
    static int length = 0x8FFFFFF; // 128 Mb
    public static void mapThis (String file) throws Exception {
        MappedByteBuffer out = new RandomAccessFile(file, "rw")
            .getChannel().map(FileChannel.MapMode.READ_WRITE, 0, length);
        byte b;
        if(!out.isLoaded()) out.load();
         for (int i = 0; i < length; i++) {
             b = out.get(i);
             manipulate(b);
    As for Bertram's solution, couldn't get it to work properly in a dynamic use case - I'm getting the input stream from IResource, and I get a ClassCastException everytime I use something different from InputStream. With that problem comes another one: InputStream.read() consuming the first byte from the file, which is a problem when dealing with PDF and DOC files, for example. Since I know the users are opening PDF files, made a quick-and-dirty workaround by inserting manually the missing byte. Really dirty one, actually - the byte changes with the file format. Below is the code I used - it works, but I'd love to see a different workaround.
    public void openFile( )
        //@@begin openFile()
            //KM files are shown in a table
            //get index of selected table row
         int i = wdContext.nodeTableContent().getLeadSelection();
         //get the name of the according object (resource)
         String name = wdContext.nodeTableContent().getTableContentElementAt(i).getObjectName();
         String path = wdContext.currentContextElement().getPath();
         try {
         RID pathRID = RID.getRID(path"/"name);
         IWDClientUser wdClientUser = WDClientUser.getCurrentUser();
         com.sap.security.api.IUser sapUser = wdClientUser.getSAPUser();
         IUser ep5User = WPUMFactory.getUserFactory().getEP5User(sapUser);
         IResourceContext resourceContext = new ResourceContext(ep5User);
         com.sapportals.wcm.repository.IResource resource = ResourceFactory.getInstance().getResource(pathRID, resourceContext);
         InputStream in = null;
         in = resource.getContent().getInputStream();
         int bSize = 10 * 1024;
         byte[] bArr = new byte[bSize];
         ByteArrayOutputStream baos = new ByteArrayOutputStream ();
         int offset = 0;
         int data;
         //dirty!
         String ext = name.substring(name.length()-3);
              if("pdf".equalsIgnoreCase(WDWebResourceType.getWebResourceTypeForFileExtension(ext).getFileExtension())) {
              byte b = '%';
              baos.write(b);     
         while ( (data=in.read(bArr)) != -1)
         baos.write(bArr);
         IWDAttributeInfo pdfAttributeInfo = wdContext.getNodeInfo().getAttribute(IPrivateKMBrowserAppCompView.IContextElement.PDF_RESOURCE);
         IWDModifiableBinaryType binaryType = (IWDModifiableBinaryType) pdfAttributeInfo.getModifiableSimpleType();
         binaryType.setFileName(name);
            binaryType.setMimeType(WDWebResourceType.getWebResourceTypeForFileExtension(ext));
         wdContext.currentContextElement().setPDFResource(baos.toByteArray());
         } catch (Exception e) {
        //@@end

  • About download file into unix file

    Hi expert,
    i use the openset to write file into unix file server.
    but why there are some space at the end of every line.
    by the way, i works very well in windows server
       DATA: DATA_TRANSFER(70).
        Data: DATA_TRANSFER type string.
        data: fine_riga1(1) TYPE X VALUE '0D0A'.
        DATA: gt_data TYPE STANDARD TABLE OF ty_data.
        Constants: ascii_tab type x value ','.
        field-symbols: <f> type any, <delim> type any.
        "Assign delimiter field such as tab or comma.
        assign ASCII_tab to <delim>.
        CLEAR VN_CNT.
        concatenate DSNU 'employee' PN-BEGDA SY-UZEIT into P_UNIX.
        OPEN DATASET P_UNIX in legacy text MODE FOR OUTPUT. " IN TEXT MODE encoding UTF-8.
        IF SY-SUBRC <> 0.
          WRITE: / 'Error on file open:', P_UNIX.
        ELSE.
          LOOP AT TI_DATA .
            CLEAR DATA_TRANSFER.
            concatenate TI_DATA-TYPE
                              TI_DATA-PERNR
                              TI_DATA-ZAUSW
                              TI_DATA-ENAME
                              TI_DATA-TERID
                              INTO DATA_TRANSFER separated by cl_abap_char_utilities=>HORIZONTAL_TAB.
            CONDENSE DATA_TRANSFER NO-GAPS.
            TRANSFER DATA_TRANSFER TO P_UNIX.
            ADD 1 TO VN_CNT.
            CLEAR DATA_TRANSFER.
          ENDLOOP.
          CLOSE DATASET P_UNIX.
        ENDIF.
        WRITE: / P_UNIX,
               / 'Transfered', VN_CNT, 'records'.
    Best Regards,
    Kevin

    Hi,
    Try this way...
    TRANSFER dobj TO dset [LENGTH len]
                                          [NO END OF LINE].
    Addition 1
    ... LENGTH len
    Effect
    This addition determines how many characters or how many bytes of data object dobj are written to the file. len is expected to be a data object of type i that contains the number of characters or bytes. In text files, the content of len specifies the number of characters that are written from the storage. For binary files, legacy text file, and legacy binary files, len specifies the number of bytes that are written to the file. The first len characters or bytes are transferred and alignment gaps are included in the structures. If the addition LENGTH is not specified, all characters or bytes are transferred.
    If the value of len is less than or equal to 0, no characters or bytes are transferred. If the file is opened as a (legacy) text file, however, a line end marker is inserted into the file by default. If the value of len is greater than the number of characters or bytes in dobj, hexadecimal 0 or blank characters are transferred to the file instead of the missing bytes or characters, depending on whether the file was opened as a (legacy) text file or a (legacy) binary file.

  • HELP..Using BufferedInputStream

    Hi I am trying to send a video file (.mpg) from a tcp server written in C to a tcp client written in Java. The server seems to be sending the bytes accurately. But on the JAva client end, the bytes are recived but each time the numbers of bytes recived are different and when I compare the file produced in Java it has some missing bytes, some repeated bytes and some delayed bytes. I have been trying for 2 weeks, with all different combination of streams (Buffered, Object, Data). From the C porgram I am sending bytes using (char*) so I assumed I would have to receive bytes, so I used BufferedInputStream...but it didn't work.....
    the following is the code i used to recive the mpg file.
    File file = new File("C:/outfilename106.mpg);
    file.createNewFile();
    FileOutputStream fout=new FileOutputStream(file);
    BufferedOutputStream out2=new BufferedOutputStream(fout);
    BufferedInputStream in2=new BufferedInputStream(socket.getInputStream());
    while(in2.read(buffer)!=-1)
              out2.write(buffer);
    it seems perhaps i am using teh wrong streams to receive video file, or the wrong way to write to a file?????or something else
    Please help!!..i have been tryimg for long..i have a project due very soon..and because of this nothing will work..thanks.....

    while(in2.read(buffer)!=-1)
              out2.write(buffer);
    int count;
    while ((count = in2.read(buffer)) != -1)
        out2.write(buffer,0,count);
    }This would be just about #1 in the FAQ if there was one.

  • Storing input stream in a buffer

    Hi, what is the best way to read an input stream and save it into a buffer?
    Thanks,
    Andrea

    Not sure if any of the following are an improvement or not. But here are just a few thoughts. Why handle all the byte array allocation yourself? IMO, it would be easier to simply use a ByteArrayOutputStream at that point. The listeners can call toByteArray() and be passed an offset and length of what was read.
    Now that I think about it, you could probably make it a bit more generic even than that. For example, here is a class I end up using all the time:
    public final class Pipe
        /** Buffer size to read in and output. */
        private static final int DEFAULT_BUFFER_SIZE = 2048;
         * Private constructor.  Use public static facade methods instead.
        private Pipe()
            super();
         * Pipes the specified binary data to the specified output stream.
         * @param   target                      Binary data to output
         * @param   out                         Stream to write
         * @throws  IOException
        public static final void pipe(final byte[] target, final OutputStream out)
            throws IOException
            assert (target != null) : "Missing byte array";
            assert (out != null) : "Missing output stream";
            pipe(new ByteArrayInputStream(target), out, true);
         * Reads from the specified input stream and returns all data as an in-memory.
         * binary array.  Note:  Since streams may be of any arbitrary size, this
         * method requires that you wrap your original stream in a {@link FiniteInputStream}.
         * Please ensure that this method is only used to read in data under, say, 2mB.
         * @param   in                          Stream to read
         * @return  byte[]                      Binary data read
         * @throws  IOException
        public static final byte[] pipe(final FiniteInputStream in)
            throws IOException
            ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
            pipe(in, byteOut, true);
            return byteOut.toByteArray();
         * Reads from the specified input stream and outputs immediately to the specified.
         * output stream.  <br>
         * <br>
         * If you have any confusion about which <code>Pipe</code> method to use, choose
         * this one.  It has the lowest memory overhead and is the most efficient.  Always
         * choose this method when streaming large amounts of data or content.
         * @param   in                          Input stream to read
         * @param   out                         Output stream to write
         * @param   close                       Close both stream if true
         * @return  long                        Byte count piped
         * @throws  IOException
        public static final long pipe(final InputStream in, final OutputStream out, final boolean close)
            throws IOException
            assert (in != null) : "Missing input stream";
            assert (out != null) : "Missing output stream";
            long bytesPiped = 0L;
            byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
            try
                int bytesRead = in.read(buffer);
                while (bytesRead >= 0)
                    if (bytesRead > 0)
                        out.write(buffer, 0, bytesRead);
                        bytesPiped = bytesPiped + bytesRead;
                    bytesRead = in.read(buffer);
                out.flush();
                return bytesPiped;
            finally
                if (close)
                    IoHelper.close(in);
                    IoHelper.close(out);
    }You simply could add the listener feature (which I do think is useful and elegant). Note the FiniteInputStream and FiniteOutputStream are just sub-classes of FilterInputStream and FilterOutputStream that allow you to limit how many bytes are piped, if desired.
    - Saish

  • DVD Drive in an Idigo iBook

    I am attempting to put a DVD drive from a graphite into an indigo iBook. The drive is functional but i found out that the two faceplates are not interchangeable. Is there a DVD type faceplate for the indigo iBook or am i stuck with a mismatched laptop if i want to keep DVD capability?

    Sorry - I assumed since the 300 - 366 were interchangeable that the 466 was as well
    I sincerely doubt there are Indigo color bezels for 466 drives that were made by Apple (although I could be wrong again). May have to just live with the color difference? Paint?
    Here are a few 'riskier' options - one being a cut away approach and the other involving a drill...
    http://the-missing-byte.com/tmb/?page_id=13
    http://www.macmod.com/content/view/604/192/

  • Verifying data

    I have a 3 step process.
    1. pars file to db
    2. send db data to 3rd party crm.
    I'd like to have some sort of checksum on the data.
    I'm thinking pull a few lines from the raw files and save it, then query the db and the crm for those records.
    Any suggestions?

    This should help you get started. IoHelper is just a separate class that closes an I/O stream and logs any exceptions it encounters.
    public final class DigestHelper extends Object
        /** Default one-way hash algorithm. */
        private static final String ALGORITHM = "SHA-256";
        /** Default hash buffer size. */
        private static final int BUFFER_SIZE = 2048;
        /** Maximum in-memory hash (2 megabytes). */
        private static final int MAX_LENGTH = 2 * 1056 * 1056;
         * Private constructor.  Class is stateless.
        private DigestHelper()
            super();
         * Calculates the one-way hash (digest) on a given input stream of any length.
         * The algorithm used with be SHA-256.  This method will invoke <code>close()#</code>
         * on the input stream passed in.
         * @param   target                      Input stream to hash
         * @return  byte[]                      One-way hash
         * @throws  IOException
        public static final byte[] computeOneWayHash(final InputStream target)
            throws IOException
            assert (target != null) : "Missing input stream";
            byte[] buffer = new byte[BUFFER_SIZE];
            DigestInputStream in = null;
            try
                in = new DigestInputStream(target, getMessageDigest());
                int bytesRead = in.read(buffer);
                while (bytesRead >= 0)
                    bytesRead = in.read(buffer);
                return in.getMessageDigest().digest();
            finally
                IoHelper.close(target);
         * Calculates the one-way hash (digest) on a given string.
         * The algorithm used with be SHA-256
         * @param   target                      String to hash
         * @return  byte[]                      One-way hash
        public static final byte[] computeOneWayHash(final String target)
            return computeOneWayHash(target.getBytes());
         * Calculates the one-way hash (digest) on a given byte array.
         * The algorithm used with be SHA-256
         * @param   target                      Binary to hash
         * @return  byte[]                      One-way hash
        public static final byte[] computeOneWayHash(final byte[] target)
            assert (target != null) : "Missing byte array";
            assert (target.length < MAX_LENGTH) : "Target exceeds maximum allowable in memory size";
            return getMessageDigest().digest(target);
         * Helper method to create a message digest to calculate one-way hashes.
         * @return  MessageDigest    Digester
        private static MessageDigest getMessageDigest()
            try
                return MessageDigest.getInstance(ALGORITHM);
            catch (NoSuchAlgorithmException e)
                throw new ConfigurationError("Unable to create " + ALGORITHM + " one-way hash", e);
    }- Saish

  • Voice chat using java rtp

    hi
    i got voice transmission and receiving in java rtp but some what delay is there
    i tried reduce the delay but still i have problem
    i tried with GSM_RTP,LINEAR,ULAW ,etc but still delay is there
    any one help me please
    source code is avaliable in :
    http://javasolution.blogspot.com/2007/04/simple-application-for-voice.html

    bendash wrote:
    My questions are:
    - Is it a good idea to implement a voice chat feature using the Java Sound API, something similar to the example above on the link?If you need to do the voice chat in Java for whatever reason, then yes...
    - Is it possible to somehow fix that delay? if yes, then how?From what I saw from glancing at that code, it's transporting the audio streams via a TCP stream. TCP streams retransmit data when it's lost, which is actually something that you don't want in a real-time application. If you lose some packets with audio data, and those are retransmitted, your receiver is getting progressively more and more behind (because the audio stream has to wait for the missing bytes to arrive before it can continue.
    For a simple application like yours, your best bet would be to divide the audio stream into buffer-sized chunks (1024 bytes might be a good buffer size), and transmit those in UDP packets. Make sure to add a packet number to the UDP packets. On the other end, just write some code so that out of order packets are ignored (so if packet 4 arrives after packet 6, for instance, you drop that packet rather than playing it after 6... so you'd get 123(silence)567...

  • Voice chat using Sound API?

    Hi there,
    I'm a university student, trying to find a way to create an application in java with voice chat feature. It will actually be a call center simulator app consisting of two parts, a server and a client part:
    The multithreaded server manages the clients, and the JPA database;
    The client's job is to login to the server, and then he'll get a randomly selected person's data and phone number by the server - in this case, IP address is the phone number, and the person is another available client. Then he can call that person, ask the questions regarding for example, a bank card (if it is a bank's call center), jot down the answers to a form, and then hang up; then the client will send said person's data to the server, who updates it in the database.
    For the voice chat part, I want to use the Java Sound API, and I've found this example:
    [Voice Chat Using Java|http://javasolution.blogspot.com/2007/04/voice-chat-using-java.html]
    But although this example works, there's a delay of 1.5 - 2 seconds in the audio.
    My questions are:
    - Is it a good idea to implement a voice chat feature using the Java Sound API, something similar to the example above on the link?
    - Is it possible to somehow fix that delay? if yes, then how?
    Also, how would you imagine/structure a program like that?
    Let me remind you that it's only a simulation, and we're not talking about actual phone-to-net calls or something like that; only LAN and internet calls, so clients should need no more than a microphone and a speaker to work with it, and also, the server shouldn't need extra hardware,too.
    Thank you in advance for your replies,
    Ben Dash
    university student

    bendash wrote:
    My questions are:
    - Is it a good idea to implement a voice chat feature using the Java Sound API, something similar to the example above on the link?If you need to do the voice chat in Java for whatever reason, then yes...
    - Is it possible to somehow fix that delay? if yes, then how?From what I saw from glancing at that code, it's transporting the audio streams via a TCP stream. TCP streams retransmit data when it's lost, which is actually something that you don't want in a real-time application. If you lose some packets with audio data, and those are retransmitted, your receiver is getting progressively more and more behind (because the audio stream has to wait for the missing bytes to arrive before it can continue.
    For a simple application like yours, your best bet would be to divide the audio stream into buffer-sized chunks (1024 bytes might be a good buffer size), and transmit those in UDP packets. Make sure to add a packet number to the UDP packets. On the other end, just write some code so that out of order packets are ignored (so if packet 4 arrives after packet 6, for instance, you drop that packet rather than playing it after 6... so you'd get 123(silence)567...

  • How do you free up memories?

    I was dumbfounded when I learned that you cannot uninstall programs from Mac. Which means even if you delete unwanted programs, you are still leaving registry files and temp files associated with the program. I bought this mac 3 days ago and have not installed anything other than Office 2004 for Mac. I currently have 35 gigs free which means 60-35 = 25. 25 gigs are being used. ON WHAT????????

    HD space is reported differently by the system than the HD manufacturers report it. The manufacturers say 1GB is 1 billion bytes while a GB is actually 1,073,741,824 bytes. Multiply those "missing" bytes by the number of GB on the HD and you will see the "lost" capacity. This is about 4.5GB.
    It is the same with PCs so this is not a Mac issue.
    Seondly, you have about 14GB of stuff pre-installed on your Mac by Apple. You can remove anything that is there without issue.
    There is no registry like in Windows, and whoever told you that you cannot uninstall anything was just plain wrong. If the app comes with an uninstaller, use it. If not, then drag and drop the app icon to the trash and empty it. If you want to use Spotlight to find the pref files that may be left behind, you can get everything.
    I see that you are a new Mac user and have poste several questions. Switching from Windows can be a little unnerving, but don't worry - it will get easier as you become more familiar with it. In the meantime, we are here for any questions that you might have.

  • MalformedInputException

    Dear Fellows,
    when I try to run the following code it throughs an Exception
    (sun.io.MalformedInputException: Missing byte-order mark)
    //Code starts here
    import java.io.*;
    public class TestClass {
    public static void main(String args[]){
    File file = new File("res/test1.txt");
    try{
         BufferedReader inbound = new BufferedReader(new InputStreamReader(new FileInputStream(file), "Unicode"));
         int b = inbound.read();
         System.out.println(b);
    }catch(Exception ex){
         System.out.println(ex);
    //Code ends here
    The file test1.txt has the following data inside the "";
    "� �H,*I��,.���*K�7��s/�/-(f7dg�M�KLO�M�+agg�p�w� �([/   "
    I will be very much greate ful if some body could help me.

    BufferedReader inbound = new BufferedReader(newInputStreamReader(new FileInputStream(file),
    "Unicode"));
    Try to use "UnicodeLittle" or "UnicodeBig" instead of
    "Unicode".Thanks. Its working fine&#9786;

  • RPAQ_GET_AF_0168 Inconsistent Results

    I used this FM successfully in another program so when I needed it again I just copied what I had and used it:
    CALL FUNCTION 'RPAQ_GET_AF_0168'
        EXPORTING
          c_it0168  = gv_pa0168
        IMPORTING
          af_values = gv_p0168_af
        TABLES
          af_fields = gt_rhtext_field.
    However, even if I pass the exactly same PA0168 record in the new program the structure gv_p0168_af is "empty" (all initial values) whereas the other program, with the same 168 record, returns actual results.
    I'm at a loss.  Any ideas as to what might be going on?

    Hello Steve,
    2 recommendations:
    - check the structures for EXPORTING, IMPORTING and TABLES. They have to be 100% consistent with the FM parameters.
    - debug the FM, specifically where the information you are expecting is taken from.
    In my opinion, this "non-delivery" (as the message says) can only be caused by a parameter-inconsistency. Even one missing byte in a data element can cause such an unexpected trouble.
    I wish you the best in your investigation. Hope this helps,
    Heinz

Maybe you are looking for

  • URL to access XML Publisher report

    How would I compose a URL to be called via a personalization button, which returns the output from an XML Publisher report?

  • How to secure Oracle Applications?

    i have implemented security mechanisms in the database,but i would like to know how to implement security in an application rather than doing so through the database? Thank you

  • Small App Store annoyance since 2.1......

    Hey everyone I just had a question that I wanted some input on... Ever since I upgraded to 2.1 on my iPhone 3g I keep getting prompted to enter my iTunes password as soon as I launch the App Store on my phone. Before the upgrade it would only prompt

  • Enable logging level

    hi all, in our company, we are maintaing users for OBIEE in the external table and admin tool. i am able set logging level for the users in the admin tool. but could not set logging level for users maintained in the external table. please let me now

  • Text copied from firefox does not paste right, not a problem using IE or Chrome

    Using firefox 35.0 on windows 7 64 bit, copying "vtamlst1" (first large gray area) on http://www.kicksfortso.com/User%27s%20Guide%201.5.0/KooKbooK/08/index.htm, then pasting into notepad, spacing all wrong. looks like most spaces dropped. Same proble