/** * Find a StorageFormat that can be used according to a file object to store a Drawing in a file * or restore it from a file respectively. * * @param file a File object to be matched * @return StorageFormat, if a matching file extension could be found, <code>null</code> otherwise */ public StorageFormat findStorageFormat(File file) { Iterator<StorageFormat> formatsIterator = myStorageFormats.iterator(); StorageFormat currentStorageFormat; while (formatsIterator.hasNext()) { currentStorageFormat = (StorageFormat) formatsIterator.next(); if (currentStorageFormat.getFileFilter().accept(file)) { return currentStorageFormat; } } return null; }
/** * Find a StorageFormat that can be used according to a FileFilter to store a Drawing in a file or * restore it from a file respectively. * * @param findFileFilter FileFilter used to identify a StorageFormat * @return StorageFormat, if a matching file extension could be found, false otherwise */ public StorageFormat findStorageFormat(FileFilter findFileFilter) { Iterator formatsIterator = myStorageFormats.iterator(); StorageFormat currentStorageFormat = null; while (formatsIterator.hasNext()) { currentStorageFormat = (StorageFormat) formatsIterator.next(); if (currentStorageFormat.getFileFilter().equals(findFileFilter)) { return currentStorageFormat; } } return null; }
private static void fromMetastoreApiStorageDescriptor( StorageDescriptor storageDescriptor, Storage.Builder builder, String tablePartitionName) { SerDeInfo serdeInfo = storageDescriptor.getSerdeInfo(); if (serdeInfo == null) { throw new PrestoException( HIVE_INVALID_METADATA, "Table storage descriptor is missing SerDe info"); } builder .setStorageFormat( StorageFormat.createNullable( serdeInfo.getSerializationLib(), storageDescriptor.getInputFormat(), storageDescriptor.getOutputFormat())) .setLocation(nullToEmpty(storageDescriptor.getLocation())) .setBucketProperty( HiveBucketProperty.fromStorageDescriptor(storageDescriptor, tablePartitionName)) .setSorted(storageDescriptor.isSetSortCols() && !storageDescriptor.getSortCols().isEmpty()) .setSkewed( storageDescriptor.isSetSkewedInfo() && storageDescriptor.getSkewedInfo().isSetSkewedColNames() && !storageDescriptor.getSkewedInfo().getSkewedColNames().isEmpty()) .setSerdeParameters( serdeInfo.getParameters() == null ? ImmutableMap.of() : serdeInfo.getParameters()); }
/** Load a Drawing from a file */ protected void loadDrawing(StorageFormat restoreFormat, String file) { try { Drawing restoredDrawing = restoreFormat.restore(file); if (restoredDrawing != null) { restoredDrawing.setTitle(file); newWindow(restoredDrawing); } else { showStatus("Unknown file type: could not open file '" + file + "'"); } } catch (IOException e) { showStatus("Error: " + e); } }
/** Save a Drawing in a file */ protected void saveDrawing(StorageFormat storeFormat, String file) { // Need a better alert than this. if (view() == null) { return; } try { String name = storeFormat.store(file, view().drawing()); view().drawing().setTitle(name); setDrawingTitle(name); } catch (IOException e) { showStatus(e.toString()); } }
/** * Register all FileFilters supported by StorageFormats * * @param fileChooser javax.swing.JFileChooser to which FileFilters are added */ public void registerFileFilters(JFileChooser fileChooser) { if (fileChooser.getDialogType() == JFileChooser.OPEN_DIALOG) { // behavior for open dialogs StorageFormat sf; for (Iterator<StorageFormat> e = myStorageFormats.iterator(); e.hasNext(); ) { sf = (StorageFormat) e.next(); if (sf.isRestoreFormat()) { fileChooser.addChoosableFileFilter(sf.getFileFilter()); } } // set a current activated file filter if a default storage Format has been defined sf = getDefaultStorageFormat(); if (sf != null && sf.isRestoreFormat()) { fileChooser.setFileFilter(sf.getFileFilter()); } } else if (fileChooser.getDialogType() == JFileChooser.SAVE_DIALOG) { // behavior for save dialogs StorageFormat sf; for (Iterator<StorageFormat> e = myStorageFormats.iterator(); e.hasNext(); ) { sf = (StorageFormat) e.next(); if (sf.isStoreFormat()) { fileChooser.addChoosableFileFilter(sf.getFileFilter()); } } // set a current activated file filter if a default storage Format has been defined sf = getDefaultStorageFormat(); if (sf != null && sf.isStoreFormat()) { fileChooser.setFileFilter(sf.getFileFilter()); } } else { // old behavior StorageFormat sf; for (Iterator<StorageFormat> e = myStorageFormats.iterator(); e.hasNext(); ) { sf = (StorageFormat) e.next(); fileChooser.addChoosableFileFilter(sf.getFileFilter()); } // set a current activated file filter if a default storage Format has been defined sf = getDefaultStorageFormat(); if (sf != null) { fileChooser.setFileFilter(sf.getFileFilter()); } } }