[a-z]+ */
- public final Version version;
- public final String ksname;
- public final String cfname;
- public final int generation;
- public final SSTableFormat.Type formatType;
- /** digest component - might be {@code null} for old, legacy sstables */
- public final Component digestComponent;
- private final int hashCode;
-
- /**
- * A descriptor that assumes CURRENT_VERSION.
- */
- @VisibleForTesting
- public Descriptor(File directory, String ksname, String cfname, int generation)
- {
- this(SSTableFormat.Type.current().info.getLatestVersion(), directory, ksname, cfname, generation, SSTableFormat.Type.current(), null);
- }
-
- /**
- * Constructor for sstable writers only.
- */
- public Descriptor(File directory, String ksname, String cfname, int generation, SSTableFormat.Type formatType)
- {
- this(formatType.info.getLatestVersion(), directory, ksname, cfname, generation, formatType, Component.digestFor(formatType.info.getLatestVersion().uncompressedChecksumType()));
- }
-
- @VisibleForTesting
- public Descriptor(String version, File directory, String ksname, String cfname, int generation, SSTableFormat.Type formatType)
- {
- this(formatType.info.getVersion(version), directory, ksname, cfname, generation, formatType, Component.digestFor(formatType.info.getLatestVersion().uncompressedChecksumType()));
- }
-
- public Descriptor(Version version, File directory, String ksname, String cfname, int generation, SSTableFormat.Type formatType, Component digestComponent)
- {
- assert version != null && directory != null && ksname != null && cfname != null && formatType.info.getLatestVersion().getClass().equals(version.getClass());
- this.version = version;
- try
- {
- this.directory = directory.getCanonicalFile();
- }
- catch (IOException e)
- {
- throw new IOError(e);
- }
- this.ksname = ksname;
- this.cfname = cfname;
- this.generation = generation;
- this.formatType = formatType;
- this.digestComponent = digestComponent;
-
- hashCode = Objects.hashCode(version, this.directory, generation, ksname, cfname, formatType);
- }
-
- public Descriptor withGeneration(int newGeneration)
- {
- return new Descriptor(version, directory, ksname, cfname, newGeneration, formatType, digestComponent);
- }
-
- public Descriptor withFormatType(SSTableFormat.Type newType)
- {
- return new Descriptor(newType.info.getLatestVersion(), directory, ksname, cfname, generation, newType, digestComponent);
- }
-
- public Descriptor withDigestComponent(Component newDigestComponent)
- {
- return new Descriptor(version, directory, ksname, cfname, generation, formatType, newDigestComponent);
- }
-
- public String tmpFilenameFor(Component component)
- {
- return filenameFor(component) + TMP_EXT;
- }
-
- public String filenameFor(Component component)
- {
- return baseFilename() + separator + component.name();
- }
-
- public String baseFilename()
- {
- StringBuilder buff = new StringBuilder();
- buff.append(directory).append(File.separatorChar);
- appendFileName(buff);
- return buff.toString();
- }
-
- private void appendFileName(StringBuilder buff)
- {
- if (!version.hasNewFileName())
- {
- buff.append(ksname).append(separator);
- buff.append(cfname).append(separator);
- }
- buff.append(version).append(separator);
- buff.append(generation);
- if (formatType != SSTableFormat.Type.LEGACY)
- buff.append(separator).append(formatType.name);
- }
-
- public String relativeFilenameFor(Component component)
- {
- final StringBuilder buff = new StringBuilder();
- appendFileName(buff);
- buff.append(separator).append(component.name());
- return buff.toString();
- }
-
- public SSTableFormat getFormat()
- {
- return formatType.info;
- }
-
- /** Return any temporary files found in the directory */
- public ListThis method handles large file system by returning {@code Long.MAX_VALUE} if the size overflow. - * See JDK-8179320 for more information.
- * - * @param file the partition - * @return the size, in bytes, of the partition or {@code 0L} if the abstract pathname does not name a partition - */ - public static long getTotalSpace(File file) - { - return handleLargeFileSystem(file.getTotalSpace()); - } - - /** - * Returns the number of unallocated bytes on the specified partition. - *This method handles large file system by returning {@code Long.MAX_VALUE} if the number of unallocated bytes - * overflow. See JDK-8179320 for more information
- * - * @param file the partition - * @return the number of unallocated bytes on the partition or {@code 0L} - * if the abstract pathname does not name a partition. - */ - public static long getFreeSpace(File file) - { - return handleLargeFileSystem(file.getFreeSpace()); - } - - /** - * Returns the number of available bytes on the specified partition. - *This method handles large file system by returning {@code Long.MAX_VALUE} if the number of available bytes - * overflow. See JDK-8179320 for more information
- * - * @param file the partition - * @return the number of available bytes on the partition or {@code 0L} - * if the abstract pathname does not name a partition. - */ - public static long getUsableSpace(File file) - { - return handleLargeFileSystem(file.getUsableSpace()); - } - - /** - * Returns the {@link FileStore} representing the file store where a file - * is located. This {@link FileStore} handles large file system by returning {@code Long.MAX_VALUE} - * from {@code FileStore#getTotalSpace()}, {@code FileStore#getUnallocatedSpace()} and {@code FileStore#getUsableSpace()} - * it the value is bigger than {@code Long.MAX_VALUE}. See JDK-8162520 - * for more information. - * - * @param path the path to the file - * @return the file store where the file is stored - */ - public static FileStore getFileStore(Path path) throws IOException - { - return new SafeFileStore(Files.getFileStore(path)); - } - - /** - * Handle large file system by returning {@code Long.MAX_VALUE} when the size overflows. - * @param size returned by the Java's FileStore methods - * @return the size or {@code Long.MAX_VALUE} if the size was bigger than {@code Long.MAX_VALUE} - */ - private static long handleLargeFileSystem(long size) - { - return size < 0 ? Long.MAX_VALUE : size; - } - - /** - * Private constructor as the class contains only static methods. - */ - private FileUtils() - { - } - - /** - * FileStore decorator used to safely handle large file system. - * - *Java's FileStore methods (getTotalSpace/getUnallocatedSpace/getUsableSpace) are limited to reporting bytes as - * signed long (2^63-1), if the filesystem is any bigger, then the size overflows. {@code SafeFileStore} will - * return {@code Long.MAX_VALUE} if the size overflow.
- * - * @see https://bugs.openjdk.java.net/browse/JDK-8162520. - */ - private static final class SafeFileStore extends FileStore - { - /** - * The decorated {@code FileStore} - */ - private final FileStore fileStore; - - public SafeFileStore(FileStore fileStore) - { - this.fileStore = fileStore; - } - - @Override - public String name() - { - return fileStore.name(); - } - - @Override - public String type() - { - return fileStore.type(); - } - - @Override - public boolean isReadOnly() - { - return fileStore.isReadOnly(); - } - - @Override - public long getTotalSpace() throws IOException - { - return handleLargeFileSystem(fileStore.getTotalSpace()); - } - - @Override - public long getUsableSpace() throws IOException - { - return handleLargeFileSystem(fileStore.getUsableSpace()); - } - - @Override - public long getUnallocatedSpace() throws IOException - { - return handleLargeFileSystem(fileStore.getUnallocatedSpace()); - } - - @Override - public boolean supportsFileAttributeView(Class extends FileAttributeView> type) - { - return fileStore.supportsFileAttributeView(type); - } - - @Override - public boolean supportsFileAttributeView(String name) - { - return fileStore.supportsFileAttributeView(name); - } - - @Override - public