@Test public void testGuessFormat() throws Exception { File f = new File(testProps.get("test.bitstream").toString()); Bitstream bs = null; BitstreamFormat result = null; BitstreamFormat pdf = BitstreamFormat.findByShortDescription(context, "Adobe PDF"); bs = Bitstream.create(context, new FileInputStream(f)); context.commit(); bs.setName(null); result = FormatIdentifier.guessFormat(context, bs); assertThat("testGuessFormat 0",result, nullValue()); bs = Bitstream.create(context, new FileInputStream(f)); bs.setName("file_without_extension."); context.commit(); result = FormatIdentifier.guessFormat(context, bs); assertThat("testGuessFormat 1",result, nullValue()); bs = Bitstream.create(context, new FileInputStream(f)); bs.setName(testProps.get("test.bitstream").toString()); context.commit(); result = FormatIdentifier.guessFormat(context, bs); assertThat("testGuessFormat 2",result.getID(), equalTo(pdf.getID())); assertThat("testGuessFormat 3",result.getMIMEType(), equalTo(pdf.getMIMEType())); assertThat("testGuessFormat 4",result.getExtensions(), equalTo(pdf.getExtensions())); }
public static BitstreamFormat guessFormat(Context context, Bitstream bitstream) throws SQLException { String filename = bitstream.getName(); if (filename == null) { return null; } filename = filename.toLowerCase(); String extension = filename; int lastDot = filename.lastIndexOf('.'); if (lastDot != -1) { extension = filename.substring(lastDot + 1); } if (extension.equals("")) { return null; } TableRowIterator tri = DatabaseManager.query(context, "SELECT bitstreamformatregistry.* FROM bitstreamformatregistry, " + "fileextension WHERE fileextension.extension LIKE ? " + "AND bitstreamformatregistry.bitstream_format_id=" + "fileextension.bitstream_format_id", extension); BitstreamFormat retFormat = null; try { if (tri.hasNext()) { retFormat = new BitstreamFormat(context, tri.next()); } else { retFormat = null; } } finally { if (tri != null) { tri.close(); } } return retFormat; }
FormatIdentifier { public static BitstreamFormat guessFormat(Context context, Bitstream bitstream) throws SQLException { String filename = bitstream.getName(); if (filename == null) { return null; } filename = filename.toLowerCase(); String extension = filename; int lastDot = filename.lastIndexOf('.'); if (lastDot != -1) { extension = filename.substring(lastDot + 1); } if (extension.equals("")) { return null; } TableRowIterator tri = DatabaseManager.query(context, "SELECT bitstreamformatregistry.* FROM bitstreamformatregistry, " + "fileextension WHERE fileextension.extension LIKE ? " + "AND bitstreamformatregistry.bitstream_format_id=" + "fileextension.bitstream_format_id", extension); BitstreamFormat retFormat = null; try { if (tri.hasNext()) { retFormat = new BitstreamFormat(context, tri.next()); } else { retFormat = null; } } finally { if (tri != null) { tri.close(); } } return retFormat; } }
FormatIdentifier { public static BitstreamFormat guessFormat(Context context, Bitstream bitstream) throws SQLException { String filename = bitstream.getName(); if (filename == null) { return null; } filename = filename.toLowerCase(); String extension = filename; int lastDot = filename.lastIndexOf('.'); if (lastDot != -1) { extension = filename.substring(lastDot + 1); } if (extension.equals("")) { return null; } TableRowIterator tri = DatabaseManager.query(context, "SELECT bitstreamformatregistry.* FROM bitstreamformatregistry, " + "fileextension WHERE fileextension.extension LIKE ? " + "AND bitstreamformatregistry.bitstream_format_id=" + "fileextension.bitstream_format_id", extension); BitstreamFormat retFormat = null; try { if (tri.hasNext()) { retFormat = new BitstreamFormat(context, tri.next()); } else { retFormat = null; } } finally { if (tri != null) { tri.close(); } } return retFormat; }  }
FormatIdentifier { public static BitstreamFormat guessFormat(Context context, Bitstream bitstream) throws SQLException { String filename = bitstream.getName(); if (filename == null) { return null; } filename = filename.toLowerCase(); String extension = filename; int lastDot = filename.lastIndexOf('.'); if (lastDot != -1) { extension = filename.substring(lastDot + 1); } if (extension.equals("")) { return null; } TableRowIterator tri = DatabaseManager.query(context, "SELECT bitstreamformatregistry.* FROM bitstreamformatregistry, " + "fileextension WHERE fileextension.extension LIKE ? " + "AND bitstreamformatregistry.bitstream_format_id=" + "fileextension.bitstream_format_id", extension); BitstreamFormat retFormat = null; try { if (tri.hasNext()) { retFormat = new BitstreamFormat(context, tri.next()); } else { retFormat = null; } } finally { if (tri != null) { tri.close(); } } return retFormat; }  static BitstreamFormat guessFormat(Context context,
            Bitstream bitstream); }
FormatIdentifier { public static BitstreamFormat guessFormat(Context context, Bitstream bitstream) throws SQLException { String filename = bitstream.getName(); if (filename == null) { return null; } filename = filename.toLowerCase(); String extension = filename; int lastDot = filename.lastIndexOf('.'); if (lastDot != -1) { extension = filename.substring(lastDot + 1); } if (extension.equals("")) { return null; } TableRowIterator tri = DatabaseManager.query(context, "SELECT bitstreamformatregistry.* FROM bitstreamformatregistry, " + "fileextension WHERE fileextension.extension LIKE ? " + "AND bitstreamformatregistry.bitstream_format_id=" + "fileextension.bitstream_format_id", extension); BitstreamFormat retFormat = null; try { if (tri.hasNext()) { retFormat = new BitstreamFormat(context, tri.next()); } else { retFormat = null; } } finally { if (tri != null) { tri.close(); } } return retFormat; }  static BitstreamFormat guessFormat(Context context,
            Bitstream bitstream);  }