Zip file out of binary (xstring)

Hi,
I try to compress (zip) binary data (for example a picture) and then give it to a html page. I use the cl_abap_gzip=>compress_binary method and it seems to work. But when I save the zip-file to harddisk over the popup at the html - page, the file could not be opened. WinZip says that it is an unvalid archive.
Can anybody help me?
Here my example coding at the OnInitialization Event of the business server page:
* event handler for data retrieval
* local variables
DATA: xsourcefile TYPE xstring.
DATA: xzippedfile TYPE xstring.
DATA: source_file_mime_type TYPE string.
DATA: xzippedcontentlength TYPE i, xzippedcontentlengthstring TYPE
string.
* References
DATA: o_mime_api TYPE REF TO if_mr_api.
* processing
* +++ Read File from MIME-Repository (binary) +++
CALL METHOD cl_mime_repository_api=>if_mr_api~get_api
  RECEIVING
    r_mr_api = o_mime_api.
CALL METHOD o_mime_api->get
  EXPORTING
    i_url              = 'SAP/ZGSD_SD_ADIS/test.gif'
*    I_CHECK_AUTHORITY  = 'X'
  IMPORTING
*    E_IS_FOLDER        =
    e_content          = xsourcefile
    e_mime_type        = source_file_mime_type
*    E_LOIO             =
*  CHANGING
*    C_LANGUAGE         =
  EXCEPTIONS
    parameter_missing  = 1
    error_occured      = 2
    not_found          = 3
    permission_failure = 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.
* +++ create ZIP-File +++
TRY.
    CALL METHOD cl_abap_gzip=>compress_binary
      EXPORTING
        raw_in                     =  xsourcefile
*    RAW_IN_LEN                 = -1
*    COMPRESS_LEVEL             = 6
      IMPORTING
        gzip_out                   = xzippedfile
        gzip_out_len               = xzippedcontentlength.
* ... Länge Casten !
    xzippedcontentlengthstring = xzippedcontentlength.
* ... Errorhandling
  CATCH cx_parameter_invalid_range . " Error-Handling
  CATCH cx_sy_buffer_overflow . " Error-Handling
  CATCH cx_sy_compression_error . " Error-Handling
ENDTRY.
* +++ Put ZIP-File in Response +++
response->set_data( xzippedfile ).
response->set_header_field( name  = if_http_header_fields=>content_type
          value = 'application/octet-stream' ).
response->set_header_field( name  =
if_http_header_fields=>content_length
          value = xzippedcontentlengthstring ).
response->set_header_field( name  = 'Content-Disposition'
value = 'inline;filename=test.zip' ).
navigation->response_complete( ).
Thanks Timo

I was on vaca, sorry for the late reply.
I can't see the video card but from what I see on the rest of the spec, those stats are extremely low.
An OS (especially modern) consumes 700~1GB RAM itself. Depending on the video cards amount of RAM, if it requires using RAM, you already only have around 1GB to share. So your hard disk will be thrashed on a system like that struggling to keep RAM managed.
The CPU is very slow, in the value line. You can look on several sites which measure various components to see where you fall for performance. For example, Passmark (fairly reliable at quick glance) puts your CPU in the mid to low (value) range and has a score of 808. A mid to high end, standard CPU these days (~$300 range) is around 10,000 and above:
http://www.cpubenchmark.net/midlow_range_cpus.html
1.7GHz is pretty slow and without any Intel-esque turbo boost, the CPU is really going to be sluggish.
I would say that laptop is designed to read email and surf the web. I think it would even struggle to play HD video, let alone render real-time modern Canvas 2d animation with any level of consistency. If you do "anything else" while the animation happens, or if the animation is fairly layered, this machine will bog down. It should be entirely visible in your task managers performance tab. Most likely you'll see the CPU peg out at 100% and memory not far behind it. Take a glimpse.
I think your entire issue is that computer, not CanvasJS/EdgeJS differences.

Similar Messages

  • Problem with compressing unicode file names in zip file

    Hi Everyone,
    I have a problem while compressing the unicode file name in a zip file. I used the below code for compressing the unicode files.
    String[] source = null;
    // C:\\TestData\\unicode_filename.txt :  unicode_filename.txt is the file created in japanesse language
    source = new String[] {"C:\\TestData\\temp_properties.xml","C:\\TestData\\unicode_filename.txt" };
    byte[] buf = new byte[1024];
    // Create the ZIP file
    String target = "C:\\TestData\\target.zip";
    ZipOutputStream out = new ZipOutputStream(new FileOutputStream(target));
    // Compress the files
    for (int i = 0; i < source.length; i++)
         FileInputStream in = new FileInputStream(source);
         // Add ZIP entry to output stream.
         String fileName;
         File tempFile;
         ZipEntry zipEntry = new ZipEntry(source[i]);
         fileName = zipEntry.getName();
    zipEntry = new ZipEntry(fileName);
    zipEntry.setMethod(ZipEntry.DEFLATED);
    getUTF8Bytes(source[i]);
    // here I'm unable to find the unicode files and not able to understand.
    out.putNextEntry(zipEntry);
    // Transfer bytes from the file to the ZIP file
    int len;
    while ((len = in.read(buf)) > 0) {
    out.write(buf, 0, len);
    // Complete the entry
    out.closeEntry();
    in.close();
    // Complete the ZIP file
    out.close();Please help me how to fix this issue.
    Thanks                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Hi,
    Thanks for your time for looking into my query.
    Please check the below code for debugging the issue and throw your comments/suggestions for fixing the issue.
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.util.zip.ZipEntry;
    import java.util.zip.ZipOutputStream;
    public class ZipTest
      public static void main(String[] args) {
              String[] source = new String[] {"C:\\TestData\\APP_Properties.xml","C:\\TestData\\??.txt" };
              byte[] buf = new byte[1024];
              try {
                   // Create the ZIP file
                   String target = "C:\\TestData\\target.zip";
                   ZipOutputStream out = new ZipOutputStream(new FileOutputStream(target));
                   // Compress the files
                   for (int i = 0; i < source.length; i++) {
                        FileInputStream in = new FileInputStream(source);
                        // Add ZIP entry to output stream.
                        String fileName;
                        File tempFile;
                        ZipEntry zipEntry = new ZipEntry(source[i]);
                        fileName = zipEntry.getName();
                        zipEntry = new ZipEntry(fileName);
                        zipEntry.setMethod(ZipEntry.DEFLATED);
                        getUTF8Bytes(source[i]);
                        out.putNextEntry(zipEntry);
                        // Transfer bytes from the file to the ZIP file
                        int len;
                        while ((len = in.read(buf)) > 0) {
                             out.write(buf, 0, len);
                        // Complete the entry
                        out.closeEntry();
                        in.close();
                   // Complete the ZIP file
                   out.close();
              } catch (IOException e) {
                   e.printStackTrace();
         private static byte[] getUTF8Bytes(String s) {
              char[] c = s.toCharArray();
              FileOutputStream file;
              try {
                   file = new FileOutputStream("C:\\TestData\\output.txt", true);
                   int len = c.length;
                   // Count the number of encoded bytes...
                   int count = 0;
                   for (int i = 0; i < len; i++) {
                        int ch = c[i];
                        if (ch <= 0x7f) {
                             count++;
                        } else if (ch <= 0x7ff) {
                             count += 2;
                        } else {
                             count += 3;
                   // Now return the encoded bytes...
                   byte[] b = new byte[count];
                   int off = 0;
                   for (int i = 0; i < len; i++) {
                        int ch = c[i];
                        if (ch <= 0x7f) {
                             b[off++] = (byte) ch;
                             file.write((byte) ch);
                        } else if (ch <= 0x7ff) {
                             b[off++] = (byte) ((ch >> 6) | 0xc0);
                             file.write((byte) ((ch >> 6) | 0xc0));
                             b[off++] = (byte) ((ch & 0x3f) | 0x80);
                             file.write((byte) ((ch & 0x3f) | 0x80));
                        } else {
                             b[off++] = (byte) ((ch >> 12) | 0xe0);
                             file.write((byte) ((ch >> 12) | 0xe0));
                             b[off++] = (byte) (((ch >> 6) & 0x3f) | 0x80);
                             file.write((byte) (((ch >> 6) & 0x3f) | 0x80));
                             b[off++] = (byte) ((ch & 0x3f) | 0x80);
                             file.write((byte) ((ch & 0x3f) | 0x80));
                   file.write((byte) '\n');
                   file.write((byte) '\r');
                   file.flush();
                   file.close();
                   return b;
              } catch (FileNotFoundException e1) {
                   e1.printStackTrace();
              } catch (IOException e1) {
                   e1.printStackTrace();
              return null;
    }Thanks
    Aravind                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Zip file is created with 0 bytes

    In my below code, I am trying to zip a folder containing files and folders. But the zip file is getting created with 0 bytes.
    Could anyone please tell me what is wrong in my coding.
    private void jButton5ZipActionPerformed(java.awt.event.ActionEvent evt)
         File sgm=new File(jTextField1Text);//jTextField1Text is the filename I am selecting from the jTextField
         File tempXML=new File(sgm.getParent());
         String[] children = tempXML.list();
         for(int i=0;i<children.length;i++)
              File renamingFile=new File(tempXML,children);
              CreateZipFile czf=new CreateZipFile();
              try
                   czf.doCreate(renamingFile);
              catch (FileNotFoundException ex)
                   ex.printStackTrace();
              catch (IOException ex)
                   ex.printStackTrace();
    ==============================
    void doCreate(File dir) throws FileNotFoundException, IOException
         String[] filenames=new String[]{dir.toString()};
         byte[] buf = new byte[1024];
         try
              // Create the ZIP file
              String outFilename = "C:\\outfile.zip";
              ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outFilename));
              for (int i=0; i<filenames.length; i++)
                   FileInputStream in = new FileInputStream(filenames);
                   // Add ZIP entry to output stream.
                   out.putNextEntry(new ZipEntry(filenames[i]));
                   // Transfer bytes from the file to the ZIP file
                   int len;
                   while ((len = in.read(buf)) > 0)
                        out.write(buf, 0, len);                    
                   // Complete the entry
                   out.closeEntry();
                   in.close();
              // Complete the ZIP file
              out.close();
         catch (IOException e)
    Message was edited by:
    Simmy

    If I give File [] filenames =
    dir.listFiles();an error is thrown for the line
    out.putNextEntry(new
    ZipEntry(filenames)); as
    cannot find symbol
    symbol: constructor ZipEntry(java.io.File)
    location: class java.util.zip.ZipEntry
    There's no constructor that accepts a File as argument. There's only this
    ZipEntry(String name)
              Creates a new zip entry with the specified name.
    ZipEntry(ZipEntry e)
              Creates a new zip entry with fields taken from the specified zip entry.
    Check the API
    http://java.sun.com/j2se/1.4.2/docs/api/java/util/zip/ZipEntry.html
    regards,
    MAnuel Leiria                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Why is my Zip file being created with size of O KB?

    I have the following code
    public static int createZip (String directory)
                       throws IOException {
         File path = new File( directory );
         File outZip = new File("c:\\wip\\sams9dbExport.zip");
         boolean boo = outZip.createNewFile();
         FilenameFilter filter = new FilenameFilter() {
            public boolean accept(File dir, String name) {
                return name.endsWith(".xml");
        if ( outZip.exists() ) System.out.println("File exists");
         System.out.println(" Files and filters made");
         // These are the files to include in the ZIP file
         String[] fileList = path.list(filter);
        // Create a buffer for reading the files
        byte[] buf = new byte[1024];
        try {
            // Create the ZIP file
            String outFilename = "sams9dbExport.zip";
            ZipOutputStream out = new ZipOutputStream( new FileOutputStream( outFilename ) );
            // Compress the files
            for ( int i=0; i < fileList.length; i++ ) {
                FileInputStream in = new FileInputStream( "c:\\wip\\"+fileList[i] );
                 System.out.println( fileList[i] );
                // Add ZIP entry to output stream.
                out.putNextEntry( new ZipEntry( "c:\\wip\\"+fileList[i] ) );
                System.out.println("Added an entry");
                // Transfer bytes from the file to the ZIP file
                int len;
                while ( ( len = in.read( buf ) ) > 0 ) {
                    out.write( buf, 0, len );
                // Complete the entry
                out.closeEntry();
                in.close();
            // Complete the ZIP file
             out.close();
        } catch (IOException e) {
             System.out.println( e.toString() );
             return 0;
        return 1;
    }And I get the following output
    SQL> @ziptest
    File exists
    Files and filters made
    AH_QUERY.xml
    Added an entry
    myclob.xml
    Added an entry
    myclob1.xml
    Added an entry
    myclob2.xml
    Added an entry
    PERSONNEL.xml
    Added an entry
    PERS_ALG.xml
    Added an entry
    sampledoc.xml
    Added an entry
    ut_ah_query1.xml
    Added an entry
    ut_provider.xml
    Added an entry
    PL/SQL procedure successfully completed.
    SQL>
    But my file is created empty. I previously added a println statement in the while loop to see if it was reading and writing bytes and it was.
    Any ideas?

    I have the following code
    public static int createZip (String directory)
    throws IOException {
    File path = new File( directory );
    File outZip = new
    = new File("c:\\wip\\sams9dbExport.zip");
    boolean boo = outZip.createNewFile();So these two lines will create sams9dbExport.zip with size 0 bytes, if file didn't exist.
    No need to do that....
    try {
    // Create the ZIP file
    String outFilename = "sams9dbExport.zip";
    ZipOutputStream out = new ZipOutputStream(
    tStream( new FileOutputStream( outFilename ) );Probably you are looking a wrong "sams9dbExport.zip" -file. Your application will create two "sams9dbExport.zip"-files, one into wip-folder with 0 bytes, and other into default directory.
    >
    But my file is created empty. I previously added a
    println statement in the while loop to see if it was
    reading and writing bytes and it was.
    Any ideas?

  • Why do all downloads get downloaded as a zip file?

    Recently I was asked about downloading a file as a zipped file. I clicked ok. I didnt pay much attention to it as I thought it was just for that particular file. Now everything I download downloads as a zip file. Anyone know how to fix?

    I have not seen this happen. Zip files get saved as Zip files. DMG files get saved as DMG files. In order to convert, and or make, a Zip file out of one or any number of files you need a program, or a feature in the OS, to create a Zip archive file with that one or many files.
    Do you have such a program installed? Like Stuffit?

  • Manual moving of .ZIP files

    If I move the rollup ZIP files out of the EntMergeDir (to temporarily
    halt
    processing) and then put them back in it later, how do I tell the
    server to
    start processing them again? Stop/Start the inventory services again?

    Okay. The server in question is a root server with its own Sybase
    database;
    the files in question are rollup ZIPs from an intermediate server. Any
    other
    ideas or suggestions, feel free.
    "Jared L Jennings" <[email protected]> wrote in
    message
    news:AJqFa.7860$[email protected]..
    > 6/10/2003, Michael Meacham wrote:
    >
    > > I had to move the .ZIP files out of the EntMergeDir to do an
    export
    > > of the database (time-critical report) to a CSV file. Now I want
    to
    > > put those files back in the EntMergeDir and let the server finish> > processing them.
    >
    > Ya, I would think(not 100% positive) that you would just put them
    back
    > in and then the rollup will kick off at the specified time in the
    > policy.
    >
    > --
    > Jared L Jennings
    > Novell Support Forums SysOp
    > Using XanaNews 1.15.2.6
    > Geek by nature, NetWare by choice.

  • Read zip files created by ZipOutputStream

    Hello :)
    I am wondering if it is possible to create a zipfile using ZipOutputStream, which can be read using ZipInputStream with out using the ZipFile work-around discussed in http://forum.java.sun.com/thread.jspa?forumID=256&threadID=492219. This is no option for me, because we have a lot of client applications deployed, which cannot easily be altered.
    Are there any (third-party) libraries which I can use?
    -M1chael

    try it
    // These are the files to include in the ZIP file
    String[] source = new String[]{"source1", "source2"};
    // Create a buffer for reading the files
    byte[] buf = new byte[1024];
    try {
    // Create the ZIP file
    String target = "target.zip";
    ZipOutputStream out = new ZipOutputStream(new FileOutputStream(target));
    // Compress the files
    for (int i=0; i<source.length; i++) {
    FileInputStream in = new FileInputStream(source);
    // Add ZIP entry to output stream.
    out.putNextEntry(new ZipEntry(source[i]));
    // Transfer bytes from the file to the ZIP file
    int len;
    while ((len = in.read(buf)) > 0) {
    out.write(buf, 0, len);
    // Complete the entry
    out.closeEntry();
    in.close();
    // Complete the ZIP file
    out.close();
    } catch (IOException e) {

  • Create Zip File In Windows and Extract Zip File In Linux

    I had created a zip file (together with directory) under Windows as follow (Code are picked from [http://www.exampledepot.com/egs/java.util.zip/CreateZip.html|http://www.exampledepot.com/egs/java.util.zip/CreateZip.html] ) :
    package sandbox;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.util.zip.ZipEntry;
    import java.util.zip.ZipOutputStream;
    * @author yan-cheng.cheok
    public class Main {
         * @param args the command line arguments
        public static void main(String[] args) {
            // These are the files to include in the ZIP file
            String[] filenames = new String[]{"MyDirectory" + File.separator + "MyFile.txt"};
            // Create a buffer for reading the files
            byte[] buf = new byte[1024];
            try {
                // Create the ZIP file
                String outFilename = "outfile.zip";
                ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outFilename));
                // Compress the files
                for (int i=0; i<filenames.length; i++) {
                    FileInputStream in = new FileInputStream(filenames);
    // Add ZIP entry to output stream.
    out.putNextEntry(new ZipEntry(filenames[i]));
    // Transfer bytes from the file to the ZIP file
    int len;
    while ((len = in.read(buf)) > 0) {
    out.write(buf, 0, len);
    // Complete the entry
    out.closeEntry();
    in.close();
    // Complete the ZIP file
    out.close();
    } catch (IOException e) {
    e.printStackTrace();
    The newly created zip file can be extracted without problem under Windows, by using  [http://www.exampledepot.com/egs/java.util.zip/GetZip.html|http://www.exampledepot.com/egs/java.util.zip/GetZip.html]
    However, I realize if I extract the newly created zip file under Linux, using modified version of  [http://www.exampledepot.com/egs/java.util.zip/GetZip.html|http://www.exampledepot.com/egs/java.util.zip/GetZip.html] . The original version doesn't check for directory using zipEntry.isDirectory()).public static boolean extractZipFile(File zipFilePath, boolean overwrite) {
    InputStream inputStream = null;
    ZipInputStream zipInputStream = null;
    boolean status = true;
    try {
    inputStream = new FileInputStream(zipFilePath);
    zipInputStream = new ZipInputStream(inputStream);
    final byte[] data = new byte[1024];
    while (true) {
    ZipEntry zipEntry = null;
    FileOutputStream outputStream = null;
    try {
    zipEntry = zipInputStream.getNextEntry();
    if (zipEntry == null) break;
    final String destination = Utils.getUserDataDirectory() + zipEntry.getName();
    if (overwrite == false) {
    if (Utils.isFileOrDirectoryExist(destination)) continue;
    if (zipEntry.isDirectory())
    Utils.createCompleteDirectoryHierarchyIfDoesNotExist(destination);
    else
    final File file = new File(destination);
    // Ensure directory is there before we write the file.
    Utils.createCompleteDirectoryHierarchyIfDoesNotExist(file.getParentFile());
    int size = zipInputStream.read(data);
    if (size > 0) {
    outputStream = new FileOutputStream(destination);
    do {
    outputStream.write(data, 0, size);
    size = zipInputStream.read(data);
    } while(size >= 0);
    catch (IOException exp) {
    log.error(null, exp);
    status = false;
    break;
    finally {
    if (outputStream != null) {
    try {
    outputStream.close();
    catch (IOException exp) {
    log.error(null, exp);
    break;
    if (zipInputStream != null) {
    try {
    zipInputStream.closeEntry();
    catch (IOException exp) {
    log.error(null, exp);
    break;
    } // while(true)
    catch (IOException exp) {
    log.error(null, exp);
    status = false;
    finally {
    if (zipInputStream != null) {
    try {
    zipInputStream.close();
    } catch (IOException ex) {
    log.error(null, ex);
    if (inputStream != null) {
    try {
    inputStream.close();
    } catch (IOException ex) {
    log.error(null, ex);
    return status;
    *"MyDirectory\MyFile.txt" instead of MyFile.txt being placed under folder MyDirectory.*
    I try to solve the problem by changing the zip file creation code to
    +String[] filenames = new String[]{"MyDirectory" + "/" + "MyFile.txt"};+
    But, is this an eligible solution, by hard-coded the seperator? Will it work under Mac OS? (I do not have a Mac to try out)
    p/s To be honest, I do a cross post at  [http://stackoverflow.com/questions/2549766/create-zip-file-in-windows-and-extract-zip-file-in-linux|http://stackoverflow.com/questions/2549766/create-zip-file-in-windows-and-extract-zip-file-in-linux] Just want to get more opinion on this.
    Edited by: yccheok on Apr 26, 2010 11:41 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Your solution lies in the File.separator constant; this constant will contain the path separator that is used by the operating system. No need to hardcode one, Java already has it.
    edit: when it comes to paths by the way, I have the bad habit of always using the front slash ( / ). This will also work under Windows and has the added benefit of not needing to be escaped.

  • Problem when streaming out a binary file

    Hi,
    I am trying to stream out a binary file to an output stream (not a file, but a socket). My file is a gzip file, and I was initially simply trying to open the
    file, read it to a a byte array, and writing it out to my output stream. However, I got corrupted data at my other end and it took me quite a bit of
    debugging hours to find out why.
    I tried writing to a file the same information I was writing to my output stream but, although my file was correct, my output stream still contained
    corrupted data.
    I think I have finally narrowed down my problem to the fact that when I try to write a 0x00 value to my output stream, everything gets ignored from this
    point until I write a 0x0a byte to my output stream. Obviously this produces corrupted data, since I need all the bytes of my binary file.
    If somebody can direct me as to how to write a 0x00 value to a socket output stream, I would really appreciate your input.
    This is a sample of my code (Right now I am writing byte by byte: not very efficient, but was the only way I found where I was getting a problem):
    // out is of type OutputStream
    if (Zipped){
         // In this case we just have to stream the file out
    File myFile = new File(fileName);
         FileInputStream inputFile = new FileInputStream(myFile);
         FileOutputStream fos = new FileOutputStream(new File("/tmp/zip.gz")); //zip.gz results in a good (not corrupted) file.
         ByteArrayOutputStream out1 = new ByteArrayOutputStream(1024);
         int bytes = (int)myFile.length();
         byte[] buffer = new byte[bytes];
         bytes = inputFile.read(buffer);
         while (bytes != -1) {
              out1.write(buffer,0,bytes);
              bytes = inputFile.read(buffer);
         inputFile.close();
         try {
              int count=0;
              bytes=out1.size();
              while (count<bytes){
                   fos.write(buffer,count,1);
    out.write(buffer,count,1); // when buffer[count] == 0x00, everything after it gets ignored until a 0x0a byte is written.
                   count++;
         } catch (IOException ioe) {
              SysLog.event("IOEXCEPTION: "+ioe);
         } catch (Exception e) {
              SysLog.event("EXCEPTION: "+e);
         fos.flush();
         fos.close();
         out.flush();
    out.close();
         return;
    }

    Actually, I had thought about that and for some time I tried getting rid of some of the header information in the gzipped file, and then I stopped doing that when I realized that part of the gzipped file is a CRC value which I believe is computed taking into account both the data of the file and the header information. If this is the case, then getting rid of part of the header would produce a corrupted file ... but then, I might be wrong in this issue.
    Anyway, to make my application more clear, what I am doing is writing the code for a cgi command which is suppossed to access information from a database, create an xml file, gzip it, and then send it to the client who requested the information.
    Therefore, what I am sending is an xml file (Content-Type: text/xml) in compressed format (Content-Encoding: gzip). Note that if I don't gzip the file and then send it uncompressed to the client, I have no problems. However, for me it is very important to gzip it because the size of the file can get very large and that would just take bandwidth unnecessarily.
    On the other hand, if I try to gunzip the file locally, I have no problem either (the file is not corrupt at the server's end). Therefore, my problem is when I stream it out.
    Any further help would be really appreciated!

  • Zip binary data and save zip file to disk at bsp

    Hi,
    I try to compress (zip) binary data (for example a picture) and then give it to a html page. I use the cl_abap_gzip=>compress_binary method and it seems to work. But when I save the zip-file to harddisk over the popup at the html - page, the file could not be opened. WinZip says that it is an unvalid archive.
    Can anybody help me?
    Here my example coding at the OnInitialization Event of the business server page:
    * event handler for data retrieval
    * local variables
    DATA: xsourcefile TYPE xstring.
    DATA: xzippedfile TYPE xstring.
    DATA: source_file_mime_type TYPE string.
    DATA: xzippedcontentlength TYPE i, xzippedcontentlengthstring TYPE
    string.
    * References
    DATA: o_mime_api TYPE REF TO if_mr_api.
    * processing
    * +++ Read File from MIME-Repository (binary) +++
    CALL METHOD cl_mime_repository_api=>if_mr_api~get_api
      RECEIVING
        r_mr_api = o_mime_api.
    CALL METHOD o_mime_api->get
      EXPORTING
        i_url              = 'SAP/ZGSD_SD_ADIS/test.gif'
    *    I_CHECK_AUTHORITY  = 'X'
      IMPORTING
    *    E_IS_FOLDER        =
        e_content          = xsourcefile
        e_mime_type        = source_file_mime_type
    *    E_LOIO             =
    *  CHANGING
    *    C_LANGUAGE         =
      EXCEPTIONS
        parameter_missing  = 1
        error_occured      = 2
        not_found          = 3
        permission_failure = 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.
    * +++ create ZIP-File +++
    TRY.
        CALL METHOD cl_abap_gzip=>compress_binary
          EXPORTING
            raw_in                     =  xsourcefile
    *    RAW_IN_LEN                 = -1
    *    COMPRESS_LEVEL             = 6
          IMPORTING
            gzip_out                   = xzippedfile
            gzip_out_len               = xzippedcontentlength.
    * ... Länge Casten !
        xzippedcontentlengthstring = xzippedcontentlength.
    * ... Errorhandling
      CATCH cx_parameter_invalid_range . " Error-Handling
      CATCH cx_sy_buffer_overflow . " Error-Handling
      CATCH cx_sy_compression_error . " Error-Handling
    ENDTRY.
    * +++ Put ZIP-File in Response +++
    response->set_data( xzippedfile ).
    response->set_header_field( name  = if_http_header_fields=>content_type
              value = 'application/octet-stream' ).
    response->set_header_field( name  =
    if_http_header_fields=>content_length
              value = xzippedcontentlengthstring ).
    response->set_header_field( name  = 'Content-Disposition'
    value = 'inline;filename=test.zip' ).
    navigation->response_complete( ).
    Thanks Timo
    PS: I posted this question also at ABAP Forum.

    Hi,
    First you need to define your ext prog in SM69.
    It is simple though, specify:
    Command name: ZZIPBIN
    OS: (your os)
    System command: /yourpath/zzipbin
    Extra params allowed: checked
    Then you need to code this:
    data: table TYPE zeu_t_btcxpm.
    CALL FUNCTION 'SXPG_COMMAND_EXECUTE'
        EXPORTING
          commandname                   = 'ZZIPBIN'
          additional_parameters         = param
          operatingsystem               = sy-opsys
          terminationwait               = 'X'
        TABLES
          exec_protocol                 = table
        EXCEPTIONS
          no_permission                 = 1
          command_not_found             = 2
          parameters_too_long           = 3
          security_risk                 = 4
          wrong_check_call_interface    = 5
          program_start_error           = 6
          program_termination_error     = 7
          x_error                       = 8
          parameter_expected            = 9
          too_many_parameters           = 10
          illegal_command               = 11
          wrong_asynchronous_parameters = 12
          cant_enq_tbtco_entry          = 13
          jobcount_generation_error     = 14
          OTHERS                        = 15.
    See also http://help.sap.com/saphelp_nw2004s/helpdata/en/c4/3a8023505211d189550000e829fbbd/frameset.htm
    Eddy
    PS.
    Put yourself on the SDN world map (http://sdn.idizaai.be/sdn_world/sdn_world.html) and earn 25 points.
    Spread the wor(l)d!

  • I dont have a internet connection at home, i connect my iphone 5 to my computer, it says i need new version of ITunes 11.2, i cant download it with out internet, i am at Library can i get ITunes 11.2 in a zipped files or exe file downloaded to my usb driv

    i dont have a internet connection at home, i connect my iphone 5 to my computer, it says i need new version of ITunes 11.2, i cant download it with out internet, i am at Library can i get ITunes 11.2 in a zipped files or exe file downloaded to my usb driv

    i can take pictures off my phone but thats it, i have some nice programs for pictures and art work and cant get them back on my phone to send them to friends and family. Also have some OLD pictures of Family on this Computer that was given to me i want to get off of it and send out but i can dragg and dropp from phone to computer but i cant drag and drop onto phone from computer and there the same jpg files, sad. i like my iphone5 and want another one but i might have to change when it time to upgrade , i dont want to, but i cant afford internet let alone a mac or pc, this one was given to me, was lucky to have saved to get the phone and service on a family plan, i have unlimited internet on phone that is my life source for internet, wish io could afford both phone and internet, its phone or internet, and with phone i have both in a way

  • Request time out - zip file processing in sharepoint 2010

    Hello All,
    I have developed web part that uploads the zip package file and then programmatically zip will extracted and all files will uploaded to picture library.
    If zip files are larger then it gets request timed out error..in production server.
    Currently in web.config executionTimeout="600". I can not increase it on production server so comfortably...
    However, with this same settings functionality works well in QA and dev environment.
    How to find the proper justification for this... I do not have access to any of the environment.
    Thanks,
    Saumil

    if it will take long time it's better to do this process asynchronously using Async application Page , also you might need to check the request length as well
    check the asynchronous page example
    http://msdn.microsoft.com/en-us/magazine/cc163725.aspx
    Hope that helps|Amr Fouad|MCTS,MCPD sharePoint 2010

  • How to place a binary zip files using sftp receiver adapter

    Hi experts,
    we got one scenario , where we need to pick the file (.zip) from local source path and place it in SFTP server path.
    we have done all configuration setting and processed a zip to SFTP server.
    but the client are saying the .zip file is not in a binary formate.
    so could any please help me and provide solution on this issue.
    regards
    raju

    hi Praveen,
    i clicked binary mode option in sender channel, and at receiver side sftp adapter channel i not found any option.
    could you please help me.
    regards
    raju

  • Recovery files out of pocket, can I download a zip or something?

    My daughter's Satellite s55-A5235 needed a new harddrive, it is still under warranty. I opted for the ship me the drive option and have it installed. She is home but we cannot find her file that has her drivers in it. We know it is out of pocket because it has her printer driver and others too. Is there a way to download a zip file? I am afraid to order the flash media as it may cross her/us in the mail as she heads back to university. Also, We are not wanting to pour money into a machine still under warranty.

    I think you're asking if there's a way to download a system recovery disc image. Unfortunately, that's not possible due to licensing restrictions. 
    As you may already know, the recovery media can be ordered at http://support.toshiba.com/repair. 
    Jim

  • How does System.out.println(). Work inside src.zip file !

    Hello guyz,
    I was just wondering how System.out.println() worked so i opened up the src.zip file and checked the source code. But could not understand it. As written i remember
    "out is an object encapsulated in the System class."
    Thats ok. But i could not understand the code.
        public final static PrintStream out = nullPrintStream();
        private static PrintStream nullPrintStream() throws NullPointerException {
         if (currentTimeMillis() > 0) {
             return null;
         throw new NullPointerException();
        }Also when i ran the DJ Decompiler it decompiled it to this:
    public class One
         public static void main(String args[])
              System.out.println("hello world");
    import java.io.PrintStream;
    public class One
        public One()
        public static void main(String args[])
            System.out.println("hello world");
    }Also, why does it need to import PrintStream ?

    Peter__Lawrey wrote:
    I was just wondering how System.out.println() worked so i opened up the src.zip file and checked the source code.This value is a place holder. This value is changed as soon as enough of the JVM is initialised for printing to work.
    Also, why does it need to import PrintStream ? It doesn't, but it is used in the code so DJ is including it just in case.Sorry,
    But i don't understand at all.

Maybe you are looking for

  • Log Entries in Table CDPOS with a Z File Append in VBAK

    Hi   I'm trying to log changes of a new field appended in VBAK in table CDPOS, I already marked the data element of this new field with the checkbox for changes, but when i make some changes in VA02 on this new file, i can't see the changes in the  m

  • Can't use Flash Player since installing Kaspersky

    I installed Kaspersky Internet Security 2009 and since then I can't play FP in Mozilla or IE. I have moved FP to the trusted zone but still not helping. Any ideas?

  • HANA as a Oracle Data Source via dblink

    Has anyone configured Oracle dblink to connect to HANA? I am trying to help out the Oracle DBA. It looks like Oracle documentation on dblink shows it uses ODBC. Any tips would be great. Thanks.

  • Significance of A/R Summary button in FD32 transaction

    If you go into FD32 to look at the customer credit on the status screen there is a "A/R SUMMARY" button. When we first chose this button we found the data to be very old and out of date. We also found that if we ran FCV1 "Create the AR Summary" it up

  • Worried my mac may be hacked. Help!

    Hi I've come home from work to find that my login screen on my mac has created a guest user for itself even though I've disabled it. When I go to change any settings I also get weird symbols coming up instead of english text (The accept button is als