Determine file type

How to determine file type given an input stream only?
private String getFileType (InputStream inputStream) {
return fileType;
}

But there must be some way to do thisWhy must there be?
There may be "magic numbers" in the stream, or there may not be.
The point was made in reply one that quite a few file types and that without some sensible choice about what options are going to be considered it could be quite infeasible.
But it's worse than that. There will be more file types tomorrow than there are today. Unless you are happy with your software failing tomorrow (or have access to java.lang.crystal.Ball) it will be quite difficult to test for tomorrow's file types.
But it's worse than that. A few minutes ago I created a file type to be used for blog entries on our intranet. Detect that one!
But it's worse than that. There is no reason why a given stream should not produce a whole lot of bytes that can be validly interpreted by two different pieces of software, each for their own ends. In other words: one stream, two (or more) types.
Again, why must there be some way to do this?

Similar Messages

  • Function to determine file type

    I am looking for a basic function that will receive a string,
    I want the function to look at the string and determine what the
    file type is, then perform another function.
    where filename = "demo.swf" or "somethingElse.pdf"
    if filename == 'swf'
    goto "10"
    else if filename == 'pdf'
    goto "20"

    You can use the String.split() method, to split the file name
    at the period.
    Then the file type will be the second item in the array:
    function getExtension (fileName:String):String {
    return fileName.split(".")[1];
    Dave -
    Adobe Community Expert
    www.blurredistinction.com
    http://www.adobe.com/communities/experts/

  • Determine file type error

    Hello to everyone.
    I am developing my year 3 project and i have run into some trouble.
    I am trying to determine whether a file is or is not a directory. Using the file.isDirectory works flawlessly, locally on my computer. I am trying to do this remotely using sockets as well. I send a File[] with all the directory contents of a specific folder.
    Doing so, causes a very few folders to be identified as directories where as others return false when checked using the isDirectory method. I have checked to see if it is a permissions problem outside Java but no such case is valid, so i am assuming that it should be within my code. As i already mentioned, working locally works just fine.
    Anyone has any idea what might be causing such a problem? Any help would really be appreciated.
    Kind regards
    Chris

    Well the way i have it returns nothing. It wont identify the files as plain files nor as directories. It just prints false (is not directory) and hangs, Here's the code:
              int selectedIndex = list.getSelectionIndex();
              System.out.println(client.rec[selectedIndex].isDirectory()); //Prints true or false if it is a directory
              if (client.rec[selectedIndex].isDirectory()) {
                   text.setText(client.rec[selectedIndex].getPath());
                   try {
                        client.sendData("getFS", text.getText());
                        client.receiveData();
                        if (client.com.equals("fileSystem")) {
                             list.removeAll();
                             addToList(client.rec);
                   } catch (IOException e) {
                        e.printStackTrace();
              } else {
                   text.setText(client.rec[selectedIndex].getPath());
              }Note that client.rec is the File[] and the SelectedIndex is the index in a list. I have tried substituting the isDirectory() with isFile() == false which enters the if statement but when selecting a file it returns a NullPointerException

  • Mailexample.sql how do you determine the file type?

    I'm using the mailexample.sql which explains how to use the demo_mail wrapper package for utl_smtp. There's a procedure for attaching text files and a procedure for attaching binary files. I've got binary files to attach to email successfully.
    How can I determine the file type so that I can use the attach_text procedure when attaching text files rather than the procedure for attaching binary files?
    Sandy

    Watch out! I think there is a bug in that code :-
    bug with PL/SQL Sample - maildemo.sql
    To answer your question - the usual way of determining a file type is to look for 'magic numbers' in the file that indicate its type. For example, Windows exe files often (always?) begin with the two letters 'MZ'. Zip files begin with 'PK'; Rar archives begin with 'Rar!'. Text files can begin with anything, and do not have any characteristic marker, but USASCII7 (which is what the format that routine is designed for - I think), is a characterset that only uses the first 7 bits of the byte. You could read the file, and if you find any bytes > 127, then you know it is not a USASCII7 file. I have seen various programs that 'sample' the first 64 or 256 bytes of a file instead of reading the whole file, and they usually get it right.
    Hope this helps.
    Takmeister

  • Removing obsolete file type associations from "Open With" menu

    Ever since I removed VMWare Fusion 3.x from my system, I've been unable to remove the Bootcamp file type associations that it created. For example, if I right-click on a PDF and choose Open With, this is a partial list of what I see:
    Adobe Acrobat Pro (default)
    Adobe Distiller (Mac) - Boot Camp partition (VMWare Fusion 3.0.0)
    Adobe Fireworks CS4
    Adobe Fireworks CS4 (Mac) - Boot Camp partition (VMWare Fusion 3.0.0)
    Adobe Illustrator CS4
    Adobe Illustrator (Mac) - Boot Camp partition (VMWare Fusion 3.0.0)
    Adobe Photoshop CS4
    Adobe Photoshop CS4 (Mac) - Boot Camp partition (VMWare Fusion 3.0.0)
    ...and on and on and on. 17 additional entries for Fusion for PDS's alone. This junk is driving me crazy.
    I've tried rebuilding the Launch Services database with MacPilot and Onyx (the recommended fix that I've found on the web), but the entries still are there even after restarting Finder and rebooting my iMac. I'm at a loss to figure out how to get rid of these.
    Can anyone help me?
    Thanks!

    They are stored in the LaunchServices database. You can give this a try, but no guarantees. If you no longer use VM Fusion then I suggest following the information below on uninstalling software.
    Rebuild LaunchServices Database
    Open the Terminal application in your Utilities folder. At the prompt paste in the following command in its entirety:
    find /System/Library/Frameworks -type f -name "lsregister" -exec {} -kill -seed -r \;
    Press RETURN.
    Wait for the Terminal prompt to return after which you can quit the Terminal.
    Uninstalling Software: The Basics
    Most OS X applications are completely self-contained "packages" that can be uninstalled by simply dragging the application to the Trash. Applications may create preference files that are stored in the /Home/Library/Preferences/ folder. Although they do nothing once you delete the associated application, they do take up some disk space. If you want you can look for them in the above location and delete them, too.
    Some applications may install an uninstaller program that can be used to remove the application. In some cases the uninstaller may be part of the application's installer, and is invoked by clicking on a Customize button that will appear during the install process.
    Some applications may install components in the /Home/Library/Applications Support/ folder. You can also check there to see if the application has created a folder. You can also delete the folder that's in the Applications Support folder. Again, they don't do anything but take up disk space once the application is trashed.
    Some applications may install a startupitem or a Log In item. Startupitems are usually installed in the /Library/StartupItems/ folder and less often in the /Home/Library/StartupItems/ folder. Log In Items are set in the Accounts preferences. Open System Preferences, click on the Accounts icon, then click on the LogIn Items tab. Locate the item in the list for the application you want to remove and click on the "-" button to delete it from the list.
    Some software use startup daemons or agents that are a new feature of the OS. Look for them in /Library/LaunchAgents/ and /Library/LaunchDaemons/ or in /Home/Library/LaunchAgents/.
    If an application installs any other files the best way to track them down is to do a Finder search using the application name or the developer name as the search term. Unfortunately Spotlight will not look in certain folders by default. You can modify Spotlight's behavior or use a third-party search utility, Easy Find, instead. Download Easy Find at VersionTracker or MacUpdate.
    Some applications install a receipt in the /Library/Receipts/ folder. Usually with the same name as the program or the developer. The item generally has a ".pkg" extension. Be sure you also delete this item as some programs use it to determine if it's already installed.
    There are also several shareware utilities that can uninstall applications:
    AppZapper
    Automaton
    Hazel
    CleanApp
    Yank
    SuperPop
    Uninstaller
    Spring Cleaning
    Look for them at VersionTracker or MacUpdate.
    For more information visit The XLab FAQs and read the FAQ on removing software.

  • Setting the file type in a file field

    Hi,
    I wonder if any body can help i am new to web application
    development, I am developing an asp application in dreamweaver 8,
    A few of my pages contain a file field which has a file
    browse button at the end of the field which works fine,
    now i want to set the default file type to *.pdf, Currently
    when i run my app in IE 7, when i click on the file browse
    button, the file browse dialog box appears but the default
    file type is *.* (All files), is it possible to set the default
    file type
    to pdf so that when the file browse dialog is displayed the
    default file type is *.pdf in stead of *.*.
    Thanks
    Fifo

    The OS just watch the extension of the file.Not always. If you create a word doc but name it with
    some other extension, the OS still can determine that
    it is a word doc.On which OS?
    if i take foo.exe and i rename foo.doc so my OSwill
    try to open it as a MS Word Document.Again, garbage in, garbage out.What you mean?
    If I create a MS Word Document for a file .doc that is not a real .doc and it is not able to read, i will just lose cpu time and a lot of memory.
    So it is important to understand if I need really to open MS Word watching what is the real file type
    Either way, you're going to be doing way too much
    work (and wheel-reinventing) if you're going to build
    your own detection scheme.In the SDK there is not any file type checker, and if eventually really exists an OS like you say that is able to read inside the file, i prefer to have my own Java class that do that work in a safe and opensource way.
    However in my first post i've given a site with some java code that do what I need, i just was asking if anyone know if there is any ready-to-work java class that is better for doing this work.

  • Adding images to rows in a table depending on file type

    Hello,
    Within Visual Composer we have a table which lists documents and contains information about the document type
    i.e. description = 'This is a Word Document', file type = 'application/msword'
    then I have uploaded the images (icons) for the different file types, created a 'Document Type' column (of type image) in the table and assigned the correct boolean statements to determine which icons are shown
    e.g. BOOL(IF(@MIMETYPE == 'application/msword', true, false))
    This is the exact steps explained in the how to: How To… Integrate BI Document Store and SAP Analytics Applications
    But just does not work? It will not display the icons even though the file type (MIMETYPE) is displayed and is correct.
    Any help much appreciated!

    Seem to have fixed the problem.
    By adding a filter before the table view it seems to allow a slight delay which allows the file types to load and the IF statements run correctly and display the correct images for the various file types.
    Still seems that there is a slight Visual Composer Issue there? (but now with a work-around)

  • How do I determine what type of Solaris installation I have ?

    I'm runnig "SunOS PSP 5.8 Generic_108528-13 sun4u sparc SUNW,Sun-Fire-480R" but I would like to determine the type of Solaris installation I have....do I have a a "development" installation ? Do I have all the SUNW developer packages ? Also what are the "types of installations" that are possible ?
    I'm thinkig about download the mysql binary (from Sunfreeware.com) and I went to the dpendencies site (http://wwws.sun.com/software/solaris/freeware/s8u7dependencies.html) to check what dependencies exist and I saw the following line (among other non "related" info.):
    mysql-3.23.43 gcmn-1.0 ncurses-5.2
    What exactly does this mean ?

    Hi
    You can check the type of solaris install from the below file
    /var/sadm/system/admin/CLUSTER
    Regards

  • Why is Get File Type.vi password protected

    Hi...  We have a code that was developed in LabVIEW 8.6...  We have a need to attempt to save this code all the way back to version 7.1...  I saved it back from 8.6 --> 8.5 --> 8.2.1 --> 8.0 with no issues...  But when I then try to save it back from 8.0 to 7.1 I encounter one LabVIEW 8 vi that has no equivalent functionality in 7.1...  And that one vi is
    C:\Program Files\National Instruments\LabVIEW 8.x\vi.lib\Utility\lvfile.llb\Get File Type.vi
    When I look at that vi in 8.x, to endeavor to see if I can replace its functionality by writing some code in 7.1, I find that the Get File Type.vi is password protected...  More out of curiousity than anything, why is that code password protected???  I wasn't aware that any of the standard purchased LabVIEW code came password protected...  Can anyone tell me why that is???  thanks...  bob..
    Solved!
    Go to Solution.

    That VI is using an internal callback into LabVIEW (i.e. non G-based code) to determine the type of the file.  I'm guessing the callback doesn't exist in 7.1, so you would need to write your own G-based implementation for getting the type of a file  in the 7.1 case.  The simplest solution would be to work with the extensions of the files...not perfect, but probably close enough assuming your files are well-named.  Also, the following VI can give you a bit more information about LabVIEW-specific files (independent of extension):
    LabVIEW 7.1\vi.lib\Utility\libraryn.llb\Librarian Get Info.vi
    Darren Nattinger, CLA
    LabVIEW Artisan and Nugget Penman

  • How to identify the file type in a safe way

    I need to identify the filetype of a file in my disc.
    I watched over internet and i've found this good site:
    http://filext.com/
    that supplys the "magic bytes" for many kind of files.
    I have also looked over internet for some ready class that identify different file types, and I have found FFident:
    http://schmidt.devlib.org/ffident/index.html
    Do you know any other Java package/class that is able to identify correctly the file types?
    Thank you,.

    The OS just watch the extension of the file.Not always. If you create a word doc but name it with
    some other extension, the OS still can determine that
    it is a word doc.On which OS?
    if i take foo.exe and i rename foo.doc so my OSwill
    try to open it as a MS Word Document.Again, garbage in, garbage out.What you mean?
    If I create a MS Word Document for a file .doc that is not a real .doc and it is not able to read, i will just lose cpu time and a lot of memory.
    So it is important to understand if I need really to open MS Word watching what is the real file type
    Either way, you're going to be doing way too much
    work (and wheel-reinventing) if you're going to build
    your own detection scheme.In the SDK there is not any file type checker, and if eventually really exists an OS like you say that is able to read inside the file, i prefer to have my own Java class that do that work in a safe and opensource way.
    However in my first post i've given a site with some java code that do what I need, i just was asking if anyone know if there is any ready-to-work java class that is better for doing this work.

  • Automator action to move a specific file type to a folder..

    've started shooting pictures in raw and jpg format. After I grab the pics from my camera, I'd like to put the raw files in a separate folder.
    I've played around a little but can't figure it out-- so I dunno if it's possible. Is there a way I can make an automator action where I enter or select the folder and run the action. It then makes a folder named RAW and moves all of a certain file type to the RAW folder. Is this possible with automator?
    I'd like it to make a folder named RAW inside the current folder I'm in or have selected.
    I think I figured this out using filter finder items, and move to specific folder, but I think I need to learn how to use variables for this to work how I want it. Do I need variables or is there another way?

    the following script should do it provided your Raw image files have extensions "raw" (do they?). If they have another extension, modify next to the last line accordingly.
    tell application "Finder"
    set theFolderName to "Raw"
    set curFolder to (folder of the front window as alias)
    -- Determine whether the specified folder exists
    if folder theFolderName of curFolder exists then
    set theFolder to folder theFolderName of curFolder
    -- Create a new folder, if it doesn't exist
    else
    set theFolder to make new folder at curFolder with properties {name:theFolderName}
    end if
    move (every file of curFolder whose name extension is "raw") to theFolder
    end tell
    Save the above script as an application using Script editor. To use it, select the folder you want to work on and run the script.

  • WRT610N certain file types have wrong time stamp

    Hi, I have searched this forum for a similar problem with no luck - so here goes...
    I have a WRT610N router using the latest firmware 1.00.03 B15. After upgrading the firmware I reset router for 30 sec., and then powerdown for 30 sec. as I have read on this forum, and yes the USB drive was disconnected before hand, but I still have this problem when creating/saving certain file types on the USB drive attached to the router.
    I have discovered that MS Word and PowerPoint files (.doc & .ppt) are saved with the correct date and time, but MS Excel, Notepad, and HTML files (.xls, .txt, and .mht) are saved with a time stamp that is one hour later!!! There may be other file types that are affected by this as well.
    Example: I create/save a Word file and also an Excel file at 1:00 PM, When I use Windows Explorer to view the details of the files on the USB drive, the Word file has a timestamp of 1:00 PM, but the Excel file has a timestamp of 2:00 PM (in the future). All other functions on the router seem to be OK.
    If I create these five file types on the C: drive they all have the same timestamps, I also have a Netgear SC101 NAS which shows the correct timestamps. I only have this problem when using the USB drive connected to the WRT610N. I tried this on 3 different computers - all have the same issue.
    This may seem like a minor issue, but Im using SmartSync Pro to back up all the drives on the LAN and it uses the file's timestamp to determine if it should be backedup or not. So Im concerned that backups may not be done properly, or God knows what it will do with files from the future!
    Im using WinXP SP3, the USB drive is a WD2500BEVS - 250GB with 4 partitions (largest is 120GB) all formatted as NTFS.
    I would appreciate it if others would try this and post their results here so I would know whether to bug Linksys for a fix, or if I have problems elsewhere in my configuration.  Thank you.

    Well, 15 days, 40 views, 0 replies.
    Could one kind sole, just one, please; startup Notepad, save an empty .txt file to the USB drive on the router, and then let me know if the file had the correct time stamp?
    Preferably someone with a ver 1 router, firmware 1.00.03 B15, and running WinXP SP3.
    Thanks in advance.

  • Is there any Java componenet that can verify file types that are being uplo

    Please advise
    What i mean is that it can actually read the header of the file to determine the file type

    define "file type"
    define "uploaded"

  • Determining image types used in pdf

    Hi,
    I was sent a pdf by a client and was wondering if there was a way to determine what types of images he used in the file.
    For example, did he use .jpg, .tif,, .eps etc.
    Thanks,
    Andrew Hutton
    [signature deleted by host]

    In the Object palette make sure Embed Image Data is ticked.

  • I want to edit the application associated with pdf files, but the pdf file type is not available on the Applications tab under edit preferences. How do I add file types?

    I am running Firefox 5.0 (Mozilla Firefox for Ubuntu canonical - 1.0) under Kubuntu 11.04.

    Thanks jscher2000, I tried your suggestion, but no joy (as expected). None of the extensions were .bin, and in fact, I can't find a single listing for handling the .bin extension in the entire (unfiltered) list.
    That's why I'm so confused. Where is Firefox getting the name "VLC.bin (default)" from in the first place?
    cor-el, I checked out the link that you posted.
    I don't have an entry for "browser.download.pluginOverrideTypes" and the entry "plugin.disable_full_page_plugin_for_types" was empty (default setting).
    My bad, but I forgot to mention in my first post that I had also tried renaming the mimetypes.rdf file in my "Application Data\Mozilla\Firefox\Profiles\xxx.default\" to .old to no avail.
    Firefox created a new, almost empty file, but it didn't change the behavior for .bin files. I removed the new file and put the old file back in place after determining that clearing the file did not help, since I am otherwise happy with my current file-type options.
    However, since the option to "Always perform this action" is grayed-out, I am looking into the possibility that the website is sending a misconfigured MIME type or is assigning "Content-Disposition: attachment" to the download. What's odd, though, is that I've never had problems getting binary files from the site in the past, and the problem started when the VLC player was installed.
    I'll post back after I check into the server header data.

Maybe you are looking for

  • Slow printing from Mac to HP Business Inkjet 2800dtn

    Hi, We have an iMac running Mac OS X 10.5.8 Indesign 5.0 CS4 Acrobat Pro 9.0.0 HP Business Inkjet 2800 driver PS v3010.107, with 76Mb Memory It's taking forever to print documents that are a few Mb in size. The documents are created with Indesign. I'

  • IDOC to SOAP scenario and transport process

    Scenario:-IDOC to SOAP: We got the WSDl file from Target system and our current scenario is working perfectly fine in Dev. Requirement: I have to send the same IDOC to two different SOAP target system with different SOAP URL WSDL structure is same on

  • Statistical Setup: Material Movements

    I am about to fill the setup table for material movements.  I plan to fill the setup table with all data but will do so by using posting date range to get smaller sets of data. Can I use the same name for all of the runs and if so do I need to make s

  • Error in inserting Task SOAINFRA.WFTASKPKG_111160

    Hi All, I have a main process which has call activity to a reusable process which in turns has a call activity to another reusable process.After successful deployment when i try to create an instance i am getting the below error.I am using Oracle BPM

  • PRINTING ISSUE - Newbie

    Hello everyone, I am new to the forum and looking for some assistance. I am writing a lottery program for school where i need to be able to print a ticket showing the number played, for how much and all the stuff that goes in the ticket. Basically, a