List of usage examples for javax.imageio IIOException IIOException
public IIOException(String message)
From source file:edu.harvard.iq.dataverse.ingest.tabulardata.impl.plugins.dta.DTAFileReaderSpi.java
@Override public boolean canDecodeInput(File file) throws IOException { if (file == null) { throw new IllegalArgumentException("file == null!"); }/*from w w w .j av a 2 s .c o m*/ if (!file.canRead()) { throw new IIOException("cannot read the input file"); } // set-up a FileChannel instance for a given file object FileChannel srcChannel = new FileInputStream(file).getChannel(); // create a read-only MappedByteBuffer MappedByteBuffer buff = srcChannel.map(FileChannel.MapMode.READ_ONLY, 0, DTA_HEADER_SIZE); //printHexDump(buff, "hex dump of the byte-buffer"); buff.rewind(); dbgLog.fine("applying the dta test\n"); byte[] hdr4 = new byte[4]; buff.get(hdr4, 0, 4); dbgLog.fine("hex dump: 1st 4bytes =>" + new String(Hex.encodeHex(hdr4)) + "<-"); if (hdr4[2] != 1) { dbgLog.fine("3rd byte is not 1: given file is not stata-dta type"); return false; } else if ((hdr4[1] != 1) && (hdr4[1] != 2)) { dbgLog.fine("2nd byte is neither 0 nor 1: this file is not stata-dta type"); return false; } else if (!stataReleaseNumber.containsKey(hdr4[0])) { dbgLog.fine("1st byte (" + hdr4[0] + ") is not within the ingestable range [rel. 3-10]: this file is NOT stata-dta type"); return false; } else { dbgLog.fine("this file is stata-dta type: " + stataReleaseNumber.get(hdr4[0]) + "(No in HEX=" + hdr4[0] + ")"); return true; } }
From source file:edu.harvard.iq.dvn.ingest.statdataio.impl.plugins.dta.DTAFileReaderSpi.java
@Override public boolean canDecodeInput(File file) throws IOException { if (file == null) { throw new IllegalArgumentException("file == null!"); }//from w w w . j av a 2 s . c om if (!file.canRead()) { throw new IIOException("cannot read the input file"); } // set-up a FileChannel instance for a given file object FileChannel srcChannel = new FileInputStream(file).getChannel(); // create a read-only MappedByteBuffer MappedByteBuffer buff = srcChannel.map(FileChannel.MapMode.READ_ONLY, 0, DTA_HEADER_SIZE); //printHexDump(buff, "hex dump of the byte-buffer"); buff.rewind(); boolean result = false; dbgLog.fine("applying the dta test\n"); byte[] hdr4 = new byte[4]; buff.get(hdr4, 0, 4); dbgLog.info("hex dump: 1st 4bytes =>" + new String(Hex.encodeHex(hdr4)) + "<-"); if (hdr4[2] != 1) { dbgLog.fine("3rd byte is not 1: given file is not stata-dta type"); return false; } else if ((hdr4[1] != 1) && (hdr4[1] != 2)) { dbgLog.fine("2nd byte is neither 0 nor 1: this file is not stata-dta type"); return false; } else if (!stataReleaseNumber.containsKey(hdr4[0])) { dbgLog.fine("1st byte (" + hdr4[0] + ") is not within the ingestable range [rel. 3-10]: this file is NOT stata-dta type"); return false; } else { dbgLog.fine("this file is stata-dta type: " + stataReleaseNumber.get(hdr4[0]) + "(No in HEX=" + hdr4[0] + ")"); return true; } }
From source file:dsfixgui.FileIO.DSFixFileController.java
/** *Writes a string to a text file//w w w . j ava 2s . c o m * * @param filePath * the path of the file to be read, including the filename * @param text * the String to be written to the file; can be more than one line. * @param overwrite * determines whether the user wants to overwrite the write file if it * already exists. If true, pre-existing file will be overwritten * @throws IIOException * if the write file already exists and the user allowed overwriting, but * the file could not be overwritten * @throws AccessDeniedException * if the write file already exists but the user didn't allow overwriting * @throws IOException * if an error occurs initializing the BufferedWriter */ public static void writeTextFile(String filePath, String text, boolean overwrite) throws IIOException, IOException, AccessDeniedException { //The file to be written File writeFile = new File(filePath); if (writeFile.exists() && overwrite) { //If file exists, try to delete it if (!writeFile.delete()) { //If file cannot be deleted, throw OIOException throw new IIOException("Could not delete pre-existing file: " + filePath); } } else if (writeFile.exists() && !overwrite) { //If file exists but is not allowed to be overwritten, throw AccessDeniedException throw new AccessDeniedException(writeFile.getPath()); } //Format each linebreak to be displayed correctly in a text file String formattedText = text.replaceAll("\n", String.format("%n")); //Initialize BufferedWriter to write string to file BufferedWriter fileWriter = new BufferedWriter(new FileWriter(writeFile)); //Write the file Scanner scanner = new Scanner(formattedText); while (scanner.hasNextLine()) { fileWriter.write(scanner.nextLine()); fileWriter.newLine(); } fileWriter.close(); }
From source file:dsfixgui.view.DSFGraphicsPane.java
public void setFPSFixKey(String newFPSFixKey) { try {/*from w ww . j a v a2 s . c o m*/ String fpsFixCfg = readTextFile(ui.getDataFolder() + "\\" + FPS_FIX_FILES[1]); ui.printConsole(WRITING_FILE[0] + FPS_FIX_FILES[1] + "..."); //The file to be written File writeFile = new File(ui.getDataFolder() + "\\" + FPS_FIX_FILES[1]); if (writeFile.exists()) { //If file exists, try to delete it if (!writeFile.delete()) { //If file cannot be deleted, throw OIOException throw new IIOException("Could not delete pre-existing file: " + FPS_FIX_FILES[1]); } } //Format each linebreak to be displayed correctly in a text file String formattedText = fpsFixCfg.replaceAll("\n", String.format("%n")); //Initialize BufferedWriter to write string to file BufferedWriter fileWriter = new BufferedWriter(new FileWriter(writeFile)); //Write the file Scanner scanner = new Scanner(formattedText); int i = 0; while (scanner.hasNextLine()) { String line = scanner.nextLine(); if (line.startsWith("Key=")) { fileWriter.write("Key=" + newFPSFixKey); fileWriter.newLine(); i++; } else if (line.length() > 1) { fileWriter.write(line); fileWriter.newLine(); i++; } else if (i == 2 || i == 4) { fileWriter.newLine(); i++; } } fileWriter.close(); scanner.close(); ui.printConsole(WRITING_FILE[1]); } catch (IOException ex) { ui.printConsole(FILES_EDITED_ERR[0] + FPS_FIX_FILES[1]); fpsFixKeyPicker.setDisable(true); } }
From source file:org.dcm4che2.tool.dcm2jpg.Dcm2Jpg.java
private ImageWriter getImageWriter(String imageWriterClass) throws IIOException { ImageWriter writer;//from www . jav a 2 s . co m for (Iterator<ImageWriter> it = ImageIO.getImageWritersByFormatName(formatName); it.hasNext();) { writer = it.next(); if ("*".equals(imageWriterClass) || writer.getClass().getName().equals(imageWriterClass)) { return writer; } } throw new IIOException("No such ImageWriter - " + imageWriterClass); }
From source file:org.sleuthkit.autopsy.coreutils.ImageUtils.java
/** * Private template method designed to be used as the implementation of * public methods that pull particular (usually meta-)data out of a image * file./* w w w. j a v a 2s .c o m*/ * * @param file the file to extract the data from * @param errorTemplate a message template used to log errors. Should * take one parameter: the file's unique path or * name. * @param propertyExtractor an implementation of {@link PropertyExtractor} * used to retrieve the specific property. * * @return the the value of the property extracted by the given * propertyExtractor * * @throws IOException if there was a problem reading the property from the * file. * * @see PropertyExtractor * @see #getImageHeight(org.sleuthkit.datamodel.AbstractFile) */ private static <T> T getImageProperty(AbstractFile file, final String errorTemplate, PropertyExtractor<T> propertyExtractor) throws IOException { try (InputStream inputStream = new BufferedInputStream(new ReadContentInputStream(file));) { try (ImageInputStream input = ImageIO.createImageInputStream(inputStream)) { if (input == null) { IIOException iioException = new IIOException("Could not create ImageInputStream."); LOGGER.log(Level.WARNING, errorTemplate + iioException.toString(), getContentPathSafe(file)); throw iioException; } Iterator<ImageReader> readers = ImageIO.getImageReaders(input); if (readers.hasNext()) { ImageReader reader = readers.next(); reader.setInput(input); try { return propertyExtractor.extract(reader); } catch (IOException ex) { LOGGER.log(Level.WARNING, errorTemplate + ex.toString(), getContentPathSafe(file)); throw ex; } finally { reader.dispose(); } } else { IIOException iioException = new IIOException("No ImageReader found."); LOGGER.log(Level.WARNING, errorTemplate + iioException.toString(), getContentPathSafe(file)); throw iioException; } } } }