Gzip only specific files extensions over sockets

I am writing a socket webserver class that gzips only HTML files back to the browser (client). If the HTML file contains any images, I will have to send that over uncompressed. I am using GZIPOutputStream for my HTML objects, and a regular DataOutputStream for my other objects. None of my images show up correctly when I use DataOutputStream alone, but when I also gzip them, they show up fine. Also, all the images/html files show up fine if I exclude all the gzipping altogether. So it seems as though I have to either gzip them all ... or none at all.
Is there a way to gzip only certain file extensions?
Thanks!

None of my images show up correctly when I use DataOutputStream alone, but when I also gzip them, they show up fine.Perhaps you aren't calling flush on the DataOutputStream (but the GZIP stream is) ?
So it seems as though I have to either gzip them all ... or none at all. Probably not, I believe there is just an error in your code.
Is there a way to gzip only certain file extensions?Sure,
if (fileShouldBeGzipped(file.getName()))
  sendGzipFile(file);
else
  sendFile(file);Of course, you must provide the fileShouldBeGzipped logic.
Are you really implementing a webserver? That is, is it using http? If so, the standard practice (protocol) is that a client adds a header field which states what type of content encoding it can deal with in the response (i.e. gzipped content). If the server is capable, it replies with its own header stating the content is indeed gzipped along with the gzipped content. This way the client knows that it must decompress the data before doing something with it.

Similar Messages

  • Pre-Configure QT 7 Installation for only specific file types

    Is there an 'ini' or similar configuration file or command line option set I can use to pre-configure QT7 to only associate with specific file types?
    I want to leave the associations for Media Player intact and have QT handle only MOV and other Apple-specific file types.

    Basic answer. No.
    You set file associations after the install of QuickTime.
    Most of it's adjustments and options are found in its Control Panel. Here you can set associations for MIME types that control the browser plug-in.
    Each user can set their own values.

  • 2012 Deduplicated volumes - hydrate only specific file types

    I have a file server with roughly 4 TB of data. We have found that turning on 2012 Dedupe feature is causing corruption with Access databases. Databases worked fine for a week or better before we turned on Dedupe. Everything else appears to work fine.
    I know I can exclude specific file types (ie. AACDB, MDB, etc).  Simply excluding them won't re-hydrate the currently deduped database files correct?
    Is there a version of the start-dedupjob -type unoptimization where I can specify a file type so that I can just hydrate specific files?

    The corruption didn't start until after I migrated these file shares over to the 2012 server and enabled dedupe
    After we first noticed the problem, we moved just the databases back to a 2008 file server and didn't have any more problems.  Due to some other issues with backups, I moved all the data on the 2012 server to another drive on the same server and left
    dedupe turned off.
    I had to wait for about a week before turning dedupe on for the new hard drive.  During that time my users were able to work in a database that didn't get moved to the 2008 server.  A couple of days after I deduped the drive they are getting corruption
    issues again.
    2012r2 file server
    Win 7 clients w/ Office 2010
    Deduplication is implemented as a filter driver over NTFS. So I can bet you have some backup application installed (SQL Server specific?) and it has own filter drivers conflicting with MS dedupe. What apps do you run on that box except SQL Server (obvious)?
    StarWind VSAN [Virtual SAN] clusters Hyper-V without SAS, Fibre Channel, SMB 3.0 or iSCSI, uses Ethernet to mirror internally mounted SATA disks between hosts.

  • Unable to change File Type for specific file extensions

    Under Preferences->File Types different file extensions are assigned a file type e.g. The file extension .pkb is assigned the file type of PL/SQL. The file type of PL/SQL then opens the Code editor.
    I have a user who would prefer to open .pkb files in the SQL Worksheet editor but I am unable to change the file type to SQL Script as the option is greyed out.
    How do I change the File Type for these extensions? Is there a preferences file I need to change?
    Version: 3.2.20.09
    Thanks for your help.

    Hi,
    There is no preference but it turns out you can manually edit one of the preferences.xml files to force PL/SQL types to use the SQL worksheet editor. For SQL Developer 3.2.20.09.87 that file is system3.2.20.09.87\o.sqldeveloper.11.2.0.9.87\preferences.xml and will be located (on Windows 7, for example) in directory C:\Users\<userid>\AppData\Roaming\SQL Developer
    No guarantee this will work in future versions of the product, but for now you can add the following two xml blocks...
    For example, for .pls, add to <extensionToContentTypeMap ...>
                <Item>
                   <Key>.pls</Key>
                   <Value>TEXT</Value>
                </Item>
    and <userExtensionList>
                <Item>
                   <docClassName>oracle.ide.db.model.SqlNode</docClassName>
                   <userExtensions class="java.util.ArrayList">
                      <Item class="oracle.ide.config.DocumentExtensions$ExtInfo">
                         <extension>.pls</extension>
                         <locked>false</locked>
                      </Item>
                   </userExtensions>
                </Item> I researched this a while back after reading through some forum thread where someone claimed the PL/SQL file extensions got opened in the SQL editor in his environment, but without stating any specific release information. Possibly it worked for him then due to different product behavior (whether intentional or a bug), or perhaps even due to the technique described above.
    Regards,
    Gary
    SQL Developer Team

  • Hiding specific file extensions

    Finder lets me choose between showing or hiding all file extensions, but is there a way of selecting which extensions to show and which to hide?
    I'd like to be able to see all my document files' extensions, but I don't need to see my application extensions.
    Thanks in avance
    Mariano

    You can change individual file attributes, such as showing the file extension with "A Better Finder Attribute" from http://www.publicspace.net/ABetterFinderAttributes/index.html
    I have used this program to mask all the file extensions for over 20,000 files that I transferred to my iMac from my old PC.

  • Automator copy only certain file extensions

    Hi,
    This should be so simple. I have tried using automater to search and filter ONLY .mp4 and .mov file extensions in a certain folder and copy it to another folder. Automator seems to work fine copying from folder to folder but copies all files to the new folder.
    For the life of me, I can't seem to get the correct script/workflow working. This should be so simple.
    Could someone please clue me in on how to do this? I would truly appreciate it!
    Matt

    You need to test if the file exists:
    tell application "Finder"
              set theList to (every file of folder "Documents:_RENDER FARM" of home whose name extension is in {"mov", "mp4"})
              repeat with theFile in theList
                        set fileName to do shell script "basename " & quoted form of POSIX path of (theFile as string)
                        set x to ((folder "Documents:Google Drive:Cinema 4d:_from render farm" of home as string) & fileName)
                        if not (exists x) then
                                  copy theFile to folder "Documents:Google Drive:Cinema 4d:_from render farm" of home
                        end if
              end repeat
    end tell

  • Binary file transfert over socket : data corupted !

    Hi everyone,
    I am trying to transfert binary files over Socket (java.net) and I get corrupted data... I know the data I write in the Socket is ok and I wonder why I don't get it right at the end.
    Does anyone know about it ?

    Ok i have re-written it without the Packet class and it know works...
    I give my code in case someone would be interested.
    ENCODER :
    public class Encoder {
         // the file to send
         private File file;
          * Constructor of the Encoder class
          * @param path the path to the file to send
         public Encoder(String path){
              this.file = new File(path);
              this.encodeFile();
          * This method contains the connection an file tranfert code
         private void encodeFile(){
              try {
                   // opening file reading stream
                   FileInputStream fis = new FileInputStream(this.file);
                   // connection...
                   Socket sock = new Socket("127.0.0.1", 5698);
                   // opening an output stream
                   BufferedOutputStream bos = new BufferedOutputStream(sock.getOutputStream(), 1024);
                   // start time
                   long start = System.currentTimeMillis();
                   // setting up the buffer
                   byte[] buffer = new byte[1024];
                   /* ---- File Transfert Loop ---- */
                   // reading for the first time
                   int read = fis.read(buffer);
                   while (read > 0){
                        bos.write(buffer);
                        bos.flush();
                        read = fis.read(buffer);
                   /* ----End Of File Transfert ---- */
                   // end time
                   long end = System.currentTimeMillis();
                   // closing streams and connection
                   fis.close();
                   bos.close();
                   sock.close();
                   // display file transfert duration
                   System.out.println("Completed in :" + (end - start) + " ms !");
              } catch (IOException e) {
                   e.printStackTrace();
    DECODER :
    public class Decoder {
         private File destFile;
         public Decoder(String path){
              try {
                   // setting up destination file
                   this.destFile = new File(path);
                   // setting up file writting stream
                   FileOutputStream fos = new FileOutputStream(this.destFile);
                   // setting up connection server
                   ServerSocket serv = new ServerSocket(5698);
                   // accepting client connection request
                   Socket sock = serv.accept();
                   // setting up reading stream for the connection
                   BufferedInputStream bis = new BufferedInputStream(sock.getInputStream());
                   // setting up byte buffer
                   byte[] buffer = new byte[1024];
                   // first reading
                   int read = bis.read(buffer);
                   while (read != -1){
                        // writting buffer content into file
                        for (int i=0; i < read; i++){
                             fos.write(buffer);
                        // reading next bytes
                        read = bis.read(buffer);
                   //closing streams
                   fos.close();
                   bis.close();
              } catch (IOException e) {
                   e.printStackTrace();

  • Jar only specific file types

    Hi Folks
    Is there any option to feed my requirement ?
    I have below folder structure
    acme/hmtl/1.html
    acme/html/2.html
    acme/html/3.css
    acme/css/2.css
    acme/css/1.css
    acme/css/3.html
    I want to create jar which should contain only html files. But the recurssive folder structure can extend to any number. And the jar should contain the exact folder structure same as source. I need to execute the command from parent folder level and it should jar all the html files in same folder structure...Any luck :(

    Your best bet - and something that's a good idea anyway - is to get hold of, and learn to use, Apache Ant. It'll do what you need, and a lot more.

  • Searching for specific file extensions etc?

    Is there a way to search for just, say: .jpegs or even 'Folder'?
    An 'advanced' search if you will?
    I know I can search and get all 'kinds'; .jpegs, folders, mail messages, .doc and then click on Kind and get them grouped.
    BUT, can I just search for .jpegs etc on my computer??
    Thank you!!

    Create a Smart Folder.
    In the Finder, do +File > New Smart Folder+
    In the grey area at the top of the Smart Folder window, click +This Mac,+ and Filename (on the left) and then the "+" sign on the right
    In the new row that opens, click the dropdown box on the left and select +File Extension.+
    Enter .jpg in the box after the word "is"
    You will get a listing of all the .jpg files on your Mac
    If you want to save the Smart Folder for ongoing use, click the Save button in the upper right corner, give your folder a name & location, then click Save

  • Permanently Hiding a specific File Extension in Finder

    Hello peeps,
    is what I'm asking for possible? What I have in mind is having it so that all images (png, jpg, etc.) in the Finder don't show their file extension. Is there a way to do this?
    Thanks, -temhawk

    It doesn't seem to be possible. I will have to hide my extensions manually, although that is easy and quick in most cases.

  • How can I list all folders that contain files with a specific file extension? I want a list that shows the parent folders of all files with a .nef extension.

    not the total path to the folder containing the files but rather just a parent folder one level up of the files.
    So file.nef that's in folder 1 that's in folder 2 that's in folder 3... I just want to list folder 1, not 2 or 3 (unless they contain files themselves in their level)

    find $HOME -iname '*.nef' 2>/dev/null | awk -F '/'   'seen[$(NF-1)]++ == 0 { print $(NF-1) }'
    This will print just one occurrence of directory
    The 'find' command files ALL *.nef files under your home directory (aka Folder)
    The 2>/dev/null throws away any error messages from things like "permissions denied" on a protected file or directory
    The 'awk' command extracts the parent directory and keeps track of whether it has displayed that directory before
    -F '/' tells awk to split fields using the / character
    NF is an awk variable that contains the number of fields in the current record
    NF-1 specifies the parent directory field, as in the last field is the file name and minus one if the parent directory
    $(NF-1) extracts the parent directory
    seen[] is a context addressable array variable (I choose the name 'seen'). That means I can use text strings as lookup keys.  The array is dynamic, so the first time I reference an element, if it doesn't exist, it is created with a nul value.
    seen[$(NF-1)] accesses the array element associated with the parent directory.
    seen[$(NF-1)]++ The ++ increments the element stored in the array associated with the parent directory key AFTER the value has been fetched for processing.  That is to say the original value is preserved (short term) and the value in the array is incremented by 1 for the next time it is accessed.
    the == 0 compares the fetched value (which occurred before it was incremented) against 0.  The first time a unique parent directory is used to access the array, a new element will be created and its value will be returned as 0 for the seen[$(NF-1)] == 0 comparison.
    On the first usage of a unique parent directory the comparison will be TRUE, so the { print $(NF-1) } action will be performed.
    After the first use of a unique parent directory name, the seen[$(NF-1)] access will return a value greater than 0, so the comparison will be FALSE and thus the { print $(NF-1)] } action will NOT be performed.
    Thus we get just one unique parent directory name no matter how many *.nef files are found.  Of course you get only one unique name, even if there are several same named sub-directories but in different paths
    You could put this into an Automator workflow using the "Run Shell Script" actions.

  • Searching directories for specific file extensions

    I wanted to try something, and that was to create a file with basic text loos it some where on the HD and make a program that would search the directories (So lets say you put in C:\bla\ ) for the file matching the extention (already set by the program) as say .doc - it would then open all of those files (while loop) and scan them recording data (which im not sure what yet) and printing specific data to a file
    most of this I know how to do including nav to the directory, what i dont know how to do is make the program scan the directory for the file and open it.

    Adrienk wrote:
    Can you give me some examples of file listing and searching?I could, but so can google.
    like links to documentation or examples of it in use?Bookmark this. [http://java.sun.com/javase/6/docs/api/]. Always have it open when you're coding or even designing with Java.
    open as in open to readStill not clear. You mean you just want your program to read in the contents of the file and manipulate them? Or do you want your program to display the file? Or do you want it to be "opened" by its default app, e.g. if it's a .doc file, open that document in Word?

  • Files sending over socket

    Here is my server-code:
      for (int i=0; i<countGamesToDownload; i++)
                                 out.write(gamesToDownload.get(i) + ".zip\n");
                                 out.flush();
                                 filename=System.getProperty("user.dir")+"\\"+ gamesToDownload.get(i)+".zip";
                                 System.out.println("Filename: " + filename);
                                 bin = new BufferedInputStream(new FileInputStream(new File(filename)));
                                 int len = 0;
                                  while ((len = bin.read(buffer)) > 0) {
                                       bout.write(buffer, 0, len);
                                       System.out.println("#");     
                                  bin.close();
                                  bout.flush();
                             }That's my client-code:
    for (GameInfo gi : gamesToDownloadVec)
                                   filename= "C:\\Temp\\" + in.readLine();
                                   System.out.println ("Filename: " + filename);
                                   bout = new BufferedOutputStream(new FileOutputStream(new File(filename)));
                                   int bytesRead = 0;
                                   while((bytesRead =bin.read(buffer))>0)
                                        bout.write(buffer, 0, bytesRead);
                                        System.out.println("#");
                                   bout.flush();
                                   bout.close();
                                  //new Unzip(new File(filename));
                             }If I only send one game everything is fine...
    but if i send more than i get as second filename: C:\Temp\null
    If i am debugging the server, i get on the server-side:
    file:\C:\Dokumente und Einstellungen\Edith\Eigene Dateien\java\eclipse-projekte\GameDownloadServer\GameList.xml is well-formed.
    Anzahl neuer Spiele: 4
    Filename: C:\Dokumente und Einstellungen\Edith\Eigene Dateien\java\eclipse-projekte\GameDownloadServer\Game1.zip
    Filename: C:\Dokumente und Einstellungen\Edith\Eigene Dateien\java\eclipse-projekte\GameDownloadServer\Game2.zip
    client-side:
    Filename: C:\Temp\Game1.zip
    Filename: C:\Temp\null
    Only one # is ok, because the file is only ablout 1800 kb and my buffer-size is 1024*50...
    I don't know where the problem is. it would be very great if anyone can help me...
    Greatings
    schaefli

    in.readLine() has returned null in the client. Check the API to see what this means.

  • Ristretto or maybe generic mime.types issue: case of file extension?

    Good day.
    Ristretto (the XFCE image viewer) wouldn't recognize the .TIF files I copied over from a Windows partition until I renamed them to .tif. Lowercase .tiff and .tif are indeed the only two file extensions that are mentioned for image/tiff in /etc/mime.types but I thought this was somewhat unexpected (and unwanted).
    Is it a per-app decision whether or not to do case-sensitive extension compares? Is it a problem? And if so, in mime.types or in ristretto?
    Regards,
    Rene

    Hi,
    for some background information about the above changed behavior, have a look at 4.2 Before Header Processes and Browser Security HTTP Headers of the APEX 4.1. release notes.
    Regards
    Patrick
    Member of the APEX development team
    My Blog: http://www.inside-oracle-apex.com
    APEX Plug-Ins: http://apex.oracle.com/plugins
    Twitter: http://www.twitter.com/patrickwolf

  • Time Machine, Migration Assistant, and copying specific files to a new machine

    Things were running fine. Then repeating kernel panics! A fresh Mountain Lion install seemed to fix things. To test whether the panics were related to some application or preference, how can I restore only my data, specifically the Aperture library, iTunes library, and iMovie library and nothing else from my Time Machine backup? In other words, how can I see the file structure of the Time Machine backup so I can copy only specific files and folders?
    Thanks for any advice!

    Hey hp12c,
    Thanks for the question. The following article may provide the information you are looking for:
    Mac Basics: Time Machine
    http://support.apple.com/kb/HT1427
    Restoring specific files or folders
    Choose Enter Time Machine from the Time Machine menu and the restore interface appears. You can literally see your windows as they appeared "back in time."
    You can use the timeline on the right side of the window to reach a certain point back in time (the timeline shows the times of all backups on your backup drive). If you don’t know exactly when you deleted or changed a file, you can use the back arrow to let Time Machine automatically travel through time to show you when that folder last changed.
    Note: Dates in pink indicate the data resides on your Time Machine backup device. Dates in white indicate the data resides on your Mac. In OS X Mountain Lion and Lion, portable Macs have the feature of local snapshots. See this article for details.
    You can also perform a Spotlight search in the Time Machine Finder Window search field to find a file. Simply type the Spotlight search field and use the back arrow to have Time Machine search through your backups to find what you are looking for.
    Before you restore a file, you can also use Quick Look to preview a file to make sure its the one you want. Highlight the file and press the Space Bar to bring up a quick look.
    To restore, select the file/folder and click the "Restore" button. The file will automatically be copied to the desktop or appropriate folder.  If the file you are restoring has another file in the same location with the same name, you will be prompted to choose which file to keep or keep both.
    Thanks,
    Matt M.

Maybe you are looking for

  • Converting a flat file to IDOC

    Greetings to All, I have a requirement where i need to convert an IDOC (flat) file to IDOC. the idoc is SHPMNT04.Presently i am trying to implement it using FCC at the sender side as the flat file is fixed length type. Can any one suggest me a better

  • NEED TO GET iCHAT

    So for whatever reason my iBook G4 running on Mac 10.4.9 does not have iChat...I may have accidentaly deleted it at some point. Could someone let me know where to find a download to install the program? I tried iChat AV 2.1, but it was unable to func

  • Using free reader, how to activate a hyperlink embedded in a pdf documnet?

    Using Windows 7. Control/click does not work.   embedded link not a webaddress that can be copied, but is a descriptive phrase.  Thanks.

  • Getting screen field values during runtime

    Hi everyone, In debugger for dynamically getting the screen field values we will be using  (SAPLMGMW)CALP-ENDPA this format to get the value of the field CALP-ENDPA. But this will give only for fields.My question is that how to get the screen field l

  • 2 HP printers - Deskjet works, Photosmart doesn't - SOLVED

    To expand a little - I'm trying to set up CUPS for local printing only, with two HPs - a Deskjet 940C and a Photosmart 420. Both get a 3-tux Perfect score at LinuxPrinting.org. I've installed hplip, and set everything up according to the install guid