/** * Returns a new path by appending an extension. * * @param extractFrom the path to extract the extension from * @param appendTo the path to append the extension to */ public static String addExtension(String extractFrom, String appendTo) { String suffix = getExtension(extractFrom); if (!suffix.isEmpty()) { return appendTo + '.' + suffix; } return appendTo; }
/** * Returns a new path by appending an extension. * * @param extractFrom the path to extract the extension from * @param appendTo the path to append the extension to */ public static String addExtension(String extractFrom, String appendTo) { String suffix = getExtension(extractFrom); if (!suffix.isEmpty()) { return appendTo + '.' + suffix; } return appendTo; }
private Location createTempLocation(String fileName) { String name; String suffix = Paths.getExtension(fileName); name = fileName.substring(0, fileName.length() - suffix.length() - 1); try { return appLocation.append(name).getTempFile('.' + suffix); } catch (IOException e) { throw Throwables.propagate(e); } }
private Location createTempLocation(String fileName) { String name; String suffix = Paths.getExtension(fileName); name = fileName.substring(0, fileName.length() - suffix.length() - 1); try { return appLocation.append(name).getTempFile('.' + suffix); } catch (IOException e) { throw Throwables.propagate(e); } }
@Override public Location get(String name, Loader loader) throws IOException { String suffix = Paths.getExtension(name); String prefix = name.substring(0, name.length() - suffix.length() - 1); Location targetLocation = baseDir.append(prefix).getTempFile('.' + suffix); loader.load(name, targetLocation); return targetLocation; } }
@Override public Location get(String name, Loader loader) throws IOException { String suffix = Paths.getExtension(name); String prefix = name.substring(0, name.length() - suffix.length() - 1); Location targetLocation = baseDir.append(prefix).getTempFile('.' + suffix); loader.load(name, targetLocation); return targetLocation; } }
private LocalFile resolveLocalFile(LocalFile localFile, Path stagingDir) throws IOException { URI uri = localFile.getURI(); String scheme = uri.getScheme(); // If local file, resolve the last modified time and the file size if (scheme == null || "file".equals(scheme)) { File file = new File(uri.getPath()); return new DefaultLocalFile(localFile.getName(), uri, file.lastModified(), file.length(), localFile.isArchive(), localFile.getPattern()); } // If have the same scheme as the location factory, resolve time and size using Location if (Objects.equals(locationFactory.getHomeLocation().toURI().getScheme(), scheme)) { Location location = locationFactory.create(uri); return new DefaultLocalFile(localFile.getName(), uri, location.lastModified(), location.length(), localFile.isArchive(), localFile.getPattern()); } // For other cases, attempt to save the URI content to local file, using support URLSteamHandler try (InputStream input = uri.toURL().openStream()) { Path tempFile = Files.createTempFile(stagingDir, localFile.getName(), Paths.getExtension(localFile.getName())); Files.copy(input, tempFile, StandardCopyOption.REPLACE_EXISTING); BasicFileAttributes attrs = Files.readAttributes(tempFile, BasicFileAttributes.class); return new DefaultLocalFile(localFile.getName(), tempFile.toUri(), attrs.lastModifiedTime().toMillis(), attrs.size(), localFile.isArchive(), localFile.getPattern()); } }
private LocalFile resolveLocalFile(LocalFile localFile, Path stagingDir) throws IOException { URI uri = localFile.getURI(); String scheme = uri.getScheme(); // If local file, resolve the last modified time and the file size if (scheme == null || "file".equals(scheme)) { File file = new File(uri.getPath()); return new DefaultLocalFile(localFile.getName(), uri, file.lastModified(), file.length(), localFile.isArchive(), localFile.getPattern()); } // If have the same scheme as the location factory, resolve time and size using Location if (Objects.equals(locationFactory.getHomeLocation().toURI().getScheme(), scheme)) { Location location = locationFactory.create(uri); return new DefaultLocalFile(localFile.getName(), uri, location.lastModified(), location.length(), localFile.isArchive(), localFile.getPattern()); } // For other cases, attempt to save the URI content to local file, using support URLSteamHandler try (InputStream input = uri.toURL().openStream()) { Path tempFile = Files.createTempFile(stagingDir, localFile.getName(), Paths.getExtension(localFile.getName())); Files.copy(input, tempFile, StandardCopyOption.REPLACE_EXISTING); BasicFileAttributes attrs = Files.readAttributes(tempFile, BasicFileAttributes.class); return new DefaultLocalFile(localFile.getName(), tempFile.toUri(), attrs.lastModifiedTime().toMillis(), attrs.size(), localFile.isArchive(), localFile.getPattern()); } }