idx int64 0 41.2k | question stringlengths 73 5.81k | target stringlengths 5 918 |
|---|---|---|
25,900 | public final URI toUri ( URI fileSystemUri , String root , Iterable < String > names , boolean directory ) { String path = toUriPath ( root , names , directory ) ; try { return new URI ( fileSystemUri . getScheme ( ) , fileSystemUri . getUserInfo ( ) , fileSystemUri . getHost ( ) , fileSystemUri . getPort ( ) , path , null , null ) ; } catch ( URISyntaxException e ) { throw new AssertionError ( e ) ; } } | Creates a URI for the path with the given root and names in the file system with the given URI . |
25,901 | public URI toUri ( JimfsPath path ) { fileStore . state ( ) . checkOpen ( ) ; return pathService . toUri ( uri , path . toAbsolutePath ( ) ) ; } | Gets the URI of the given path in this file system . |
25,902 | public JimfsPath toPath ( URI uri ) { fileStore . state ( ) . checkOpen ( ) ; return pathService . fromUri ( uri ) ; } | Converts the given URI into a path in this file system . |
25,903 | public static PathMatcher getPathMatcher ( String syntaxAndPattern , String separators , ImmutableSet < PathNormalization > normalizations ) { int syntaxSeparator = syntaxAndPattern . indexOf ( ':' ) ; checkArgument ( syntaxSeparator > 0 , "Must be of the form 'syntax:pattern': %s" , syntaxAndPattern ) ; String syntax = Ascii . toLowerCase ( syntaxAndPattern . substring ( 0 , syntaxSeparator ) ) ; String pattern = syntaxAndPattern . substring ( syntaxSeparator + 1 ) ; switch ( syntax ) { case "glob" : pattern = GlobToRegex . toRegex ( pattern , separators ) ; case "regex" : return fromRegex ( pattern , normalizations ) ; default : throw new UnsupportedOperationException ( "Invalid syntax: " + syntaxAndPattern ) ; } } | Perhaps so assuming Path always canonicalizes its separators |
25,904 | private static boolean startsWith ( List < ? > list , List < ? > other ) { return list . size ( ) >= other . size ( ) && list . subList ( 0 , other . size ( ) ) . equals ( other ) ; } | Returns true if list starts with all elements of other in the same order . |
25,905 | private boolean isNormal ( ) { if ( getNameCount ( ) == 0 || ( getNameCount ( ) == 1 && ! isAbsolute ( ) ) ) { return true ; } boolean foundNonParentName = isAbsolute ( ) ; boolean normal = true ; for ( Name name : names ) { if ( name . equals ( Name . PARENT ) ) { if ( foundNonParentName ) { normal = false ; break ; } } else { if ( name . equals ( Name . SELF ) ) { normal = false ; break ; } foundNonParentName = true ; } } return normal ; } | Returns whether or not this path is in a normalized form . It s normal if it both contains no . names and contains no .. names in a location other than the start of the path . |
25,906 | JimfsPath resolve ( Name name ) { if ( name . toString ( ) . isEmpty ( ) ) { return this ; } return pathService . createPathInternal ( root , ImmutableList . < Name > builder ( ) . addAll ( names ) . add ( name ) . build ( ) ) ; } | Resolves the given name against this path . The name is assumed not to be a root name . |
25,907 | public JimfsPath emptyPath ( ) { JimfsPath result = emptyPath ; if ( result == null ) { result = createPathInternal ( null , ImmutableList . of ( Name . EMPTY ) ) ; emptyPath = result ; return result ; } return result ; } | Returns an empty path which has a single name the empty string . |
25,908 | public JimfsPath createRoot ( Name root ) { return createPath ( checkNotNull ( root ) , ImmutableList . < Name > of ( ) ) ; } | Returns a root path with the given name . |
25,909 | public JimfsPath createRelativePath ( Iterable < Name > names ) { return createPath ( null , ImmutableList . copyOf ( names ) ) ; } | Returns a relative path with the given names . |
25,910 | public JimfsPath parsePath ( String first , String ... more ) { String joined = type . joiner ( ) . join ( Iterables . filter ( Lists . asList ( first , more ) , NOT_EMPTY ) ) ; return toPath ( type . parsePath ( joined ) ) ; } | Parses the given strings as a path . |
25,911 | public int hash ( JimfsPath path ) { int hash = 31 ; hash = 31 * hash + getFileSystem ( ) . hashCode ( ) ; final Name root = path . root ( ) ; final ImmutableList < Name > names = path . names ( ) ; if ( equalityUsesCanonicalForm ) { hash = 31 * hash + ( root == null ? 0 : root . hashCode ( ) ) ; for ( Name name : names ) { hash = 31 * hash + name . hashCode ( ) ; } } else { hash = 31 * hash + ( root == null ? 0 : root . toString ( ) . hashCode ( ) ) ; for ( Name name : names ) { hash = 31 * hash + name . toString ( ) . hashCode ( ) ; } } return hash ; } | Creates a hash code for the given path . |
25,912 | public URI toUri ( URI fileSystemUri , JimfsPath path ) { checkArgument ( path . isAbsolute ( ) , "path (%s) must be absolute" , path ) ; String root = String . valueOf ( path . root ( ) ) ; Iterable < String > names = Iterables . transform ( path . names ( ) , Functions . toStringFunction ( ) ) ; return type . toUri ( fileSystemUri , root , names , Files . isDirectory ( path , NOFOLLOW_LINKS ) ) ; } | Returns the URI for the given path . The given file system URI is the base against which the path is resolved to create the returned URI . |
25,913 | public DirectoryEntry get ( Name name ) { int index = bucketIndex ( name , table . length ) ; DirectoryEntry entry = table [ index ] ; while ( entry != null ) { if ( name . equals ( entry . name ( ) ) ) { return entry ; } entry = entry . next ; } return null ; } | Returns the entry for the given name in this table or null if no such entry exists . |
25,914 | public void link ( Name name , File file ) { DirectoryEntry entry = new DirectoryEntry ( this , checkNotReserved ( name , "link" ) , file ) ; put ( entry ) ; file . linked ( entry ) ; } | Links the given name to the given file in this directory . |
25,915 | public void unlink ( Name name ) { DirectoryEntry entry = remove ( checkNotReserved ( name , "unlink" ) ) ; entry . file ( ) . unlinked ( ) ; } | Unlinks the given name from the file it is linked to . |
25,916 | public ImmutableSortedSet < Name > snapshot ( ) { ImmutableSortedSet . Builder < Name > builder = new ImmutableSortedSet . Builder < > ( Name . displayOrdering ( ) ) ; for ( DirectoryEntry entry : this ) { if ( ! isReserved ( entry . name ( ) ) ) { builder . add ( entry . name ( ) ) ; } } return builder . build ( ) ; } | Creates an immutable sorted snapshot of the names this directory contains excluding . and .. . |
25,917 | public DirectoryEntry requireDirectory ( Path pathForException ) throws NoSuchFileException , NotDirectoryException { requireExists ( pathForException ) ; if ( ! file ( ) . isDirectory ( ) ) { throw new NotDirectoryException ( pathForException . toString ( ) ) ; } return this ; } | Checks that this entry exists and links to a directory throwing an exception if not . |
25,918 | public DirectoryEntry requireSymbolicLink ( Path pathForException ) throws NoSuchFileException , NotLinkException { requireExists ( pathForException ) ; if ( ! file ( ) . isSymbolicLink ( ) ) { throw new NotLinkException ( pathForException . toString ( ) ) ; } return this ; } | Checks that this entry exists and links to a symbolic link throwing an exception if not . |
25,919 | private static < V > ListenableFuture < V > closedChannelFuture ( ) { SettableFuture < V > future = SettableFuture . create ( ) ; future . setException ( new ClosedChannelException ( ) ) ; return future ; } | Immediate future indicating that the channel is closed . |
25,920 | public static FileSystem newFileSystem ( String name , Configuration configuration ) { try { URI uri = new URI ( URI_SCHEME , name , null , null ) ; return newFileSystem ( uri , configuration ) ; } catch ( URISyntaxException e ) { throw new IllegalArgumentException ( e ) ; } } | Creates a new in - memory file system with the given configuration . |
25,921 | public final synchronized ImmutableSet < String > getAttributeNames ( String view ) { if ( attributes == null ) { return ImmutableSet . of ( ) ; } return ImmutableSet . copyOf ( attributes . row ( view ) . keySet ( ) ) ; } | Returns the names of the attributes contained in the given attribute view in the file s attributes table . |
25,922 | final synchronized ImmutableSet < String > getAttributeKeys ( ) { if ( attributes == null ) { return ImmutableSet . of ( ) ; } ImmutableSet . Builder < String > builder = ImmutableSet . builder ( ) ; for ( Table . Cell < String , String , Object > cell : attributes . cellSet ( ) ) { builder . add ( cell . getRowKey ( ) + ':' + cell . getColumnKey ( ) ) ; } return builder . build ( ) ; } | Returns the attribute keys contained in the attributes map for the file . |
25,923 | public final synchronized Object getAttribute ( String view , String attribute ) { if ( attributes == null ) { return null ; } return attributes . get ( view , attribute ) ; } | Gets the value of the given attribute in the given view . |
25,924 | public final synchronized void setAttribute ( String view , String attribute , Object value ) { if ( attributes == null ) { attributes = HashBasedTable . create ( ) ; } attributes . put ( view , attribute , value ) ; } | Sets the given attribute in the given view to the given value . |
25,925 | public final synchronized void deleteAttribute ( String view , String attribute ) { if ( attributes != null ) { attributes . remove ( view , attribute ) ; } } | Deletes the given attribute from the given view . |
25,926 | protected static RuntimeException unsettable ( String view , String attribute , boolean create ) { checkNotCreate ( view , attribute , create ) ; throw new IllegalArgumentException ( "cannot set attribute '" + view + ":" + attribute + "'" ) ; } | Throws a runtime exception indicating that the given attribute cannot be set . |
25,927 | protected static void checkNotCreate ( String view , String attribute , boolean create ) { if ( create ) { throw new UnsupportedOperationException ( "cannot set attribute '" + view + ":" + attribute + "' during file creation" ) ; } } | Checks that the attribute is not being set by the user on file creation throwing an unsupported operation exception if it is . |
25,928 | protected static < T > T checkType ( String view , String attribute , Object value , Class < T > type ) { checkNotNull ( value ) ; if ( type . isInstance ( value ) ) { return type . cast ( value ) ; } throw invalidType ( view , attribute , value , type ) ; } | Checks that the given value is of the given type returning the value if so and throwing an exception if not . |
25,929 | protected static IllegalArgumentException invalidType ( String view , String attribute , Object value , Class < ? > ... expectedTypes ) { Object expected = expectedTypes . length == 1 ? expectedTypes [ 0 ] : "one of " + Arrays . toString ( expectedTypes ) ; throw new IllegalArgumentException ( "invalid type " + value . getClass ( ) + " for attribute '" + view + ":" + attribute + "': expected " + expected ) ; } | Throws an illegal argument exception indicating that the given value is not one of the expected types for the given attribute . |
25,930 | private String parseUncRoot ( String path , String original ) { Matcher uncMatcher = UNC_ROOT . matcher ( path ) ; if ( uncMatcher . find ( ) ) { String host = uncMatcher . group ( 2 ) ; if ( host == null ) { throw new InvalidPathException ( original , "UNC path is missing hostname" ) ; } String share = uncMatcher . group ( 3 ) ; if ( share == null ) { throw new InvalidPathException ( original , "UNC path is missing sharename" ) ; } return path . substring ( uncMatcher . start ( ) , uncMatcher . end ( ) ) ; } else { throw new InvalidPathException ( original , "Invalid UNC path" ) ; } } | Parse the root of a UNC - style path throwing an exception if the path does not start with a valid UNC root . |
25,931 | private void endBlocking ( boolean completed ) throws AsynchronousCloseException { synchronized ( blockingThreads ) { blockingThreads . remove ( Thread . currentThread ( ) ) ; } end ( completed ) ; } | Ends a blocking operation throwing an exception if the thread was interrupted while blocking or if the channel was closed from another thread . |
25,932 | static Name simple ( String name ) { switch ( name ) { case "." : return SELF ; case ".." : return PARENT ; default : return new Name ( name , name ) ; } } | Creates a new name with no normalization done on the given string . |
25,933 | private void expandIfNecessary ( int minBlockCount ) { if ( minBlockCount > blocks . length ) { this . blocks = Arrays . copyOf ( blocks , nextPowerOf2 ( minBlockCount ) ) ; } } | lower - level methods dealing with the blocks array |
25,934 | private void prepareForWrite ( long pos , long len ) throws IOException { long end = pos + len ; int lastBlockIndex = blockCount - 1 ; int endBlockIndex = blockIndex ( end - 1 ) ; if ( endBlockIndex > lastBlockIndex ) { int additionalBlocksNeeded = endBlockIndex - lastBlockIndex ; disk . allocate ( this , additionalBlocksNeeded ) ; } if ( pos > size ) { long remaining = pos - size ; int blockIndex = blockIndex ( size ) ; byte [ ] block = blocks [ blockIndex ] ; int off = offsetInBlock ( size ) ; remaining -= zero ( block , off , length ( off , remaining ) ) ; while ( remaining > 0 ) { block = blocks [ ++ blockIndex ] ; remaining -= zero ( block , 0 , length ( remaining ) ) ; } size = pos ; } } | Prepares for a write of len bytes starting at position pos . |
25,935 | private byte [ ] blockForWrite ( int index ) throws IOException { if ( index >= blockCount ) { int additionalBlocksNeeded = index - blockCount + 1 ; disk . allocate ( this , additionalBlocksNeeded ) ; } return blocks [ index ] ; } | Gets the block at the given index expanding to create the block if necessary . |
25,936 | private static int zero ( byte [ ] block , int offset , int len ) { Util . zero ( block , offset , len ) ; return len ; } | Zeroes len bytes in the given block starting at the given offset . Returns len . |
25,937 | private static int put ( byte [ ] block , int offset , byte [ ] b , int off , int len ) { System . arraycopy ( b , off , block , offset , len ) ; return len ; } | Puts the given slice of the given array at the given offset in the given block . |
25,938 | private static int put ( byte [ ] block , int offset , ByteBuffer buf ) { int len = Math . min ( block . length - offset , buf . remaining ( ) ) ; buf . get ( block , offset , len ) ; return len ; } | Puts the contents of the given byte buffer at the given offset in the given block . |
25,939 | private static int get ( byte [ ] block , int offset , byte [ ] b , int off , int len ) { System . arraycopy ( block , offset , b , off , len ) ; return len ; } | Reads len bytes starting at the given offset in the given block into the given slice of the given byte array . |
25,940 | private static int get ( byte [ ] block , int offset , ByteBuffer buf , int len ) { buf . put ( block , offset , len ) ; return len ; } | Reads len bytes starting at the given offset in the given block into the given byte buffer . |
25,941 | public < C extends Closeable > C register ( C resource ) { checkOpen ( ) ; registering . incrementAndGet ( ) ; try { checkOpen ( ) ; resources . add ( resource ) ; return resource ; } finally { registering . decrementAndGet ( ) ; } } | Registers the given resource to be closed when the file system is closed . Should be called when the resource is opened . |
25,942 | public static int nextPowerOf2 ( int n ) { if ( n == 0 ) { return 1 ; } int b = Integer . highestOneBit ( n ) ; return b == n ? n : b << 1 ; } | Returns the next power of 2 > = n . |
25,943 | static void checkNoneNull ( Iterable < ? > objects ) { if ( ! ( objects instanceof ImmutableCollection ) ) { for ( Object o : objects ) { checkNotNull ( o ) ; } } } | Checks that no element in the given iterable is null throwing NPE if any is . |
25,944 | DirectoryEntry lookUpWithLock ( JimfsPath path , Set < ? super LinkOption > options ) throws IOException { store . readLock ( ) . lock ( ) ; try { return lookUp ( path , options ) ; } finally { store . readLock ( ) . unlock ( ) ; } } | Attempt to look up the file at the given path . |
25,945 | private DirectoryEntry lookUp ( JimfsPath path , Set < ? super LinkOption > options ) throws IOException { return store . lookUp ( workingDirectory , path , options ) ; } | Looks up the file at the given path without locking . |
25,946 | public ImmutableSortedSet < Name > snapshotWorkingDirectoryEntries ( ) { store . readLock ( ) . lock ( ) ; try { ImmutableSortedSet < Name > names = workingDirectory . snapshot ( ) ; workingDirectory . updateAccessTime ( ) ; return names ; } finally { store . readLock ( ) . unlock ( ) ; } } | Snapshots the entries of the working directory of this view . |
25,947 | public ImmutableMap < Name , Long > snapshotModifiedTimes ( JimfsPath path ) throws IOException { ImmutableMap . Builder < Name , Long > modifiedTimes = ImmutableMap . builder ( ) ; store . readLock ( ) . lock ( ) ; try { Directory dir = ( Directory ) lookUp ( path , Options . FOLLOW_LINKS ) . requireDirectory ( path ) . file ( ) ; for ( DirectoryEntry entry : dir ) { if ( ! entry . name ( ) . equals ( Name . SELF ) && ! entry . name ( ) . equals ( Name . PARENT ) ) { modifiedTimes . put ( entry . name ( ) , entry . file ( ) . getLastModifiedTime ( ) ) ; } } return modifiedTimes . build ( ) ; } finally { store . readLock ( ) . unlock ( ) ; } } | Returns a snapshot mapping the names of each file in the directory at the given path to the last modified time of that file . |
25,948 | public boolean isSameFile ( JimfsPath path , FileSystemView view2 , JimfsPath path2 ) throws IOException { if ( ! isSameFileSystem ( view2 ) ) { return false ; } store . readLock ( ) . lock ( ) ; try { File file = lookUp ( path , Options . FOLLOW_LINKS ) . fileOrNull ( ) ; File file2 = view2 . lookUp ( path2 , Options . FOLLOW_LINKS ) . fileOrNull ( ) ; return file != null && Objects . equals ( file , file2 ) ; } finally { store . readLock ( ) . unlock ( ) ; } } | Returns whether or not the two given paths locate the same file . The second path is located using the given view rather than this file view . |
25,949 | public Directory createDirectory ( JimfsPath path , FileAttribute < ? > ... attrs ) throws IOException { return ( Directory ) createFile ( path , store . directoryCreator ( ) , true , attrs ) ; } | Creates a new directory at the given path . The given attributes will be set on the new file if possible . |
25,950 | public SymbolicLink createSymbolicLink ( JimfsPath path , JimfsPath target , FileAttribute < ? > ... attrs ) throws IOException { if ( ! store . supportsFeature ( Feature . SYMBOLIC_LINKS ) ) { throw new UnsupportedOperationException ( ) ; } return ( SymbolicLink ) createFile ( path , store . symbolicLinkCreator ( target ) , true , attrs ) ; } | Creates a new symbolic link at the given path with the given target . The given attributes will be set on the new file if possible . |
25,951 | public RegularFile getOrCreateRegularFile ( JimfsPath path , Set < OpenOption > options , FileAttribute < ? > ... attrs ) throws IOException { checkNotNull ( path ) ; if ( ! options . contains ( CREATE_NEW ) ) { RegularFile file = lookUpRegularFile ( path , options ) ; if ( file != null ) { return file ; } } if ( options . contains ( CREATE ) || options . contains ( CREATE_NEW ) ) { return getOrCreateRegularFileWithWriteLock ( path , options , attrs ) ; } else { throw new NoSuchFileException ( path . toString ( ) ) ; } } | Gets the regular file at the given path creating it if it doesn t exist and the given options specify that it should be created . |
25,952 | private RegularFile lookUpRegularFile ( JimfsPath path , Set < OpenOption > options ) throws IOException { store . readLock ( ) . lock ( ) ; try { DirectoryEntry entry = lookUp ( path , options ) ; if ( entry . exists ( ) ) { File file = entry . file ( ) ; if ( ! file . isRegularFile ( ) ) { throw new FileSystemException ( path . toString ( ) , null , "not a regular file" ) ; } return open ( ( RegularFile ) file , options ) ; } else { return null ; } } finally { store . readLock ( ) . unlock ( ) ; } } | Looks up the regular file at the given path throwing an exception if the file isn t a regular file . Returns null if the file did not exist . |
25,953 | private static RegularFile open ( RegularFile file , Set < OpenOption > options ) { if ( options . contains ( TRUNCATE_EXISTING ) && options . contains ( WRITE ) ) { file . writeLock ( ) . lock ( ) ; try { file . truncate ( 0 ) ; } finally { file . writeLock ( ) . unlock ( ) ; } } file . opened ( ) ; return file ; } | Opens the given regular file with the given options truncating it if necessary and incrementing its open count . Returns the given file . |
25,954 | public JimfsPath readSymbolicLink ( JimfsPath path ) throws IOException { if ( ! store . supportsFeature ( Feature . SYMBOLIC_LINKS ) ) { throw new UnsupportedOperationException ( ) ; } SymbolicLink symbolicLink = ( SymbolicLink ) lookUpWithLock ( path , Options . NOFOLLOW_LINKS ) . requireSymbolicLink ( path ) . file ( ) ; return symbolicLink . target ( ) ; } | Returns the target of the symbolic link at the given path . |
25,955 | public void checkAccess ( JimfsPath path ) throws IOException { lookUpWithLock ( path , Options . FOLLOW_LINKS ) . requireExists ( path ) ; } | Checks access to the file at the given path for the given modes . Since access controls are not implemented for this file system this just checks that the file exists . |
25,956 | public void link ( JimfsPath link , FileSystemView existingView , JimfsPath existing ) throws IOException { checkNotNull ( link ) ; checkNotNull ( existingView ) ; checkNotNull ( existing ) ; if ( ! store . supportsFeature ( Feature . LINKS ) ) { throw new UnsupportedOperationException ( ) ; } if ( ! isSameFileSystem ( existingView ) ) { throw new FileSystemException ( link . toString ( ) , existing . toString ( ) , "can't link: source and target are in different file system instances" ) ; } Name linkName = link . name ( ) ; store . writeLock ( ) . lock ( ) ; try { File existingFile = existingView . lookUp ( existing , Options . FOLLOW_LINKS ) . requireExists ( existing ) . file ( ) ; if ( ! existingFile . isRegularFile ( ) ) { throw new FileSystemException ( link . toString ( ) , existing . toString ( ) , "can't link: not a regular file" ) ; } Directory linkParent = lookUp ( link , Options . NOFOLLOW_LINKS ) . requireDoesNotExist ( link ) . directory ( ) ; linkParent . link ( linkName , existingFile ) ; linkParent . updateModifiedTime ( ) ; } finally { store . writeLock ( ) . unlock ( ) ; } } | Creates a hard link at the given link path to the regular file at the given path . The existing file must exist and must be a regular file . The given file system view must belong to the same file system as this view . |
25,957 | public void deleteFile ( JimfsPath path , DeleteMode deleteMode ) throws IOException { store . writeLock ( ) . lock ( ) ; try { DirectoryEntry entry = lookUp ( path , Options . NOFOLLOW_LINKS ) . requireExists ( path ) ; delete ( entry , deleteMode , path ) ; } finally { store . writeLock ( ) . unlock ( ) ; } } | Deletes the file at the given absolute path . |
25,958 | private void delete ( DirectoryEntry entry , DeleteMode deleteMode , JimfsPath pathForException ) throws IOException { Directory parent = entry . directory ( ) ; File file = entry . file ( ) ; checkDeletable ( file , deleteMode , pathForException ) ; parent . unlink ( entry . name ( ) ) ; parent . updateModifiedTime ( ) ; file . deleted ( ) ; } | Deletes the given directory entry from its parent directory . |
25,959 | private void checkDeletable ( File file , DeleteMode mode , Path path ) throws IOException { if ( file . isRootDirectory ( ) ) { throw new FileSystemException ( path . toString ( ) , null , "can't delete root directory" ) ; } if ( file . isDirectory ( ) ) { if ( mode == DeleteMode . NON_DIRECTORY_ONLY ) { throw new FileSystemException ( path . toString ( ) , null , "can't delete: is a directory" ) ; } checkEmpty ( ( ( Directory ) file ) , path ) ; } else if ( mode == DeleteMode . DIRECTORY_ONLY ) { throw new FileSystemException ( path . toString ( ) , null , "can't delete: is not a directory" ) ; } if ( file == workingDirectory && ! path . isAbsolute ( ) ) { throw new FileSystemException ( path . toString ( ) , null , "invalid argument" ) ; } } | Checks that the given file can be deleted throwing an exception if it can t . |
25,960 | public void copy ( JimfsPath source , FileSystemView destView , JimfsPath dest , Set < CopyOption > options , boolean move ) throws IOException { checkNotNull ( source ) ; checkNotNull ( destView ) ; checkNotNull ( dest ) ; checkNotNull ( options ) ; boolean sameFileSystem = isSameFileSystem ( destView ) ; File sourceFile ; File copyFile = null ; lockBoth ( store . writeLock ( ) , destView . store . writeLock ( ) ) ; try { DirectoryEntry sourceEntry = lookUp ( source , options ) . requireExists ( source ) ; DirectoryEntry destEntry = destView . lookUp ( dest , Options . NOFOLLOW_LINKS ) ; Directory sourceParent = sourceEntry . directory ( ) ; sourceFile = sourceEntry . file ( ) ; Directory destParent = destEntry . directory ( ) ; if ( move && sourceFile . isDirectory ( ) ) { if ( sameFileSystem ) { checkMovable ( sourceFile , source ) ; checkNotAncestor ( sourceFile , destParent , destView ) ; } else { checkDeletable ( sourceFile , DeleteMode . ANY , source ) ; } } if ( destEntry . exists ( ) ) { if ( destEntry . file ( ) . equals ( sourceFile ) ) { return ; } else if ( options . contains ( REPLACE_EXISTING ) ) { destView . delete ( destEntry , DeleteMode . ANY , dest ) ; } else { throw new FileAlreadyExistsException ( dest . toString ( ) ) ; } } if ( move && sameFileSystem ) { sourceParent . unlink ( source . name ( ) ) ; sourceParent . updateModifiedTime ( ) ; destParent . link ( dest . name ( ) , sourceFile ) ; destParent . updateModifiedTime ( ) ; } else { AttributeCopyOption attributeCopyOption = AttributeCopyOption . NONE ; if ( move ) { attributeCopyOption = AttributeCopyOption . BASIC ; } else if ( options . contains ( COPY_ATTRIBUTES ) ) { attributeCopyOption = sameFileSystem ? AttributeCopyOption . ALL : AttributeCopyOption . BASIC ; } copyFile = destView . store . copyWithoutContent ( sourceFile , attributeCopyOption ) ; destParent . link ( dest . name ( ) , copyFile ) ; destParent . updateModifiedTime ( ) ; lockSourceAndCopy ( sourceFile , copyFile ) ; if ( move ) { delete ( sourceEntry , DeleteMode . ANY , source ) ; } } } finally { destView . store . writeLock ( ) . unlock ( ) ; store . writeLock ( ) . unlock ( ) ; } if ( copyFile != null ) { try { sourceFile . copyContentTo ( copyFile ) ; } finally { unlockSourceAndCopy ( sourceFile , copyFile ) ; } } } | Copies or moves the file at the given source path to the given dest path . |
25,961 | private void checkNotAncestor ( File source , Directory destParent , FileSystemView destView ) throws IOException { if ( ! isSameFileSystem ( destView ) ) { return ; } Directory current = destParent ; while ( true ) { if ( current . equals ( source ) ) { throw new IOException ( "invalid argument: can't move directory into a subdirectory of itself" ) ; } if ( current . isRootDirectory ( ) ) { return ; } else { current = current . parent ( ) ; } } } | Checks that source is not an ancestor of dest throwing an exception if it is . |
25,962 | private void lockSourceAndCopy ( File sourceFile , File copyFile ) { sourceFile . opened ( ) ; ReadWriteLock sourceLock = sourceFile . contentLock ( ) ; if ( sourceLock != null ) { sourceLock . readLock ( ) . lock ( ) ; } ReadWriteLock copyLock = copyFile . contentLock ( ) ; if ( copyLock != null ) { copyLock . writeLock ( ) . lock ( ) ; } } | Locks source and copy files before copying content . Also marks the source file as opened so that its content won t be deleted until after the copy if it is deleted . |
25,963 | private void unlockSourceAndCopy ( File sourceFile , File copyFile ) { ReadWriteLock sourceLock = sourceFile . contentLock ( ) ; if ( sourceLock != null ) { sourceLock . readLock ( ) . unlock ( ) ; } ReadWriteLock copyLock = copyFile . contentLock ( ) ; if ( copyLock != null ) { copyLock . writeLock ( ) . unlock ( ) ; } sourceFile . closed ( ) ; } | Unlocks source and copy files after copying content . Also closes the source file so its content can be deleted if it was deleted . |
25,964 | public < V extends FileAttributeView > V getFileAttributeView ( FileLookup lookup , Class < V > type ) { return store . getFileAttributeView ( lookup , type ) ; } | Returns a file attribute view using the given lookup callback . |
25,965 | public < V extends FileAttributeView > V getFileAttributeView ( final JimfsPath path , Class < V > type , final Set < ? super LinkOption > options ) { return store . getFileAttributeView ( new FileLookup ( ) { public File lookup ( ) throws IOException { return lookUpWithLock ( path , options ) . requireExists ( path ) . file ( ) ; } } , type ) ; } | Returns a file attribute view for the given path in this view . |
25,966 | public < A extends BasicFileAttributes > A readAttributes ( JimfsPath path , Class < A > type , Set < ? super LinkOption > options ) throws IOException { File file = lookUpWithLock ( path , options ) . requireExists ( path ) . file ( ) ; return store . readAttributes ( file , type ) ; } | Reads attributes of the file located by the given path in this view as an object . |
25,967 | public ImmutableMap < String , Object > readAttributes ( JimfsPath path , String attributes , Set < ? super LinkOption > options ) throws IOException { File file = lookUpWithLock ( path , options ) . requireExists ( path ) . file ( ) ; return store . readAttributes ( file , attributes ) ; } | Reads attributes of the file located by the given path in this view as a map . |
25,968 | public void setAttribute ( JimfsPath path , String attribute , Object value , Set < ? super LinkOption > options ) throws IOException { File file = lookUpWithLock ( path , options ) . requireExists ( path ) . file ( ) ; store . setAttribute ( file , attribute , value ) ; } | Sets the given attribute to the given value on the file located by the given path in this view . |
25,969 | public void setInitialAttributes ( File file , FileAttribute < ? > ... attrs ) { for ( int i = 0 ; i < defaultValues . size ( ) ; i ++ ) { FileAttribute < ? > attribute = defaultValues . get ( i ) ; int separatorIndex = attribute . name ( ) . indexOf ( ':' ) ; String view = attribute . name ( ) . substring ( 0 , separatorIndex ) ; String attr = attribute . name ( ) . substring ( separatorIndex + 1 ) ; file . setAttribute ( view , attr , attribute . value ( ) ) ; } for ( FileAttribute < ? > attr : attrs ) { setAttribute ( file , attr . name ( ) , attr . value ( ) , true ) ; } } | Sets all initial attributes for the given file including the given attributes if possible . |
25,970 | public void copyAttributes ( File file , File copy , AttributeCopyOption copyOption ) { switch ( copyOption ) { case ALL : file . copyAttributes ( copy ) ; break ; case BASIC : file . copyBasicAttributes ( copy ) ; break ; default : } } | Copies the attributes of the given file to the given copy file . |
25,971 | public void setAttribute ( File file , String attribute , Object value , boolean create ) { String view = getViewName ( attribute ) ; String attr = getSingleAttribute ( attribute ) ; setAttributeInternal ( file , view , attr , value , create ) ; } | Sets the value of the given attribute to the given value for the given file . |
25,972 | DirectoryEntry lookUp ( File workingDirectory , JimfsPath path , Set < ? super LinkOption > options ) throws IOException { state . checkOpen ( ) ; return tree . lookUp ( workingDirectory , path , options ) ; } | Looks up the file at the given path using the given link options . If the path is relative the lookup is relative to the given working directory . |
25,973 | Supplier < SymbolicLink > symbolicLinkCreator ( JimfsPath target ) { state . checkOpen ( ) ; return factory . symbolicLinkCreator ( target ) ; } | Returns a supplier that creates a new symbolic link with the given target . |
25,974 | void setInitialAttributes ( File file , FileAttribute < ? > ... attrs ) { state . checkOpen ( ) ; attributes . setInitialAttributes ( file , attrs ) ; } | Sets initial attributes on the given file . Sets default attributes first then attempts to set the given user - provided attributes . |
25,975 | ImmutableMap < String , Object > readAttributes ( File file , String attributes ) { state . checkOpen ( ) ; return this . attributes . readAttributes ( file , attributes ) ; } | Returns a map containing the attributes described by the given string mapped to their values . |
25,976 | void setAttribute ( File file , String attribute , Object value ) { state . checkOpen ( ) ; attributes . setAttribute ( file , attribute , value , false ) ; } | Sets the given attribute to the given value for the given file . |
25,977 | private Integer getUniqueId ( Object object ) { Integer id = idCache . get ( object ) ; if ( id == null ) { id = uidGenerator . incrementAndGet ( ) ; Integer existing = idCache . putIfAbsent ( object , id ) ; if ( existing != null ) { return existing ; } } return id ; } | Returns an ID that is guaranteed to be the same for any invocation with equal objects . |
25,978 | public static Configuration forCurrentPlatform ( ) { String os = System . getProperty ( "os.name" ) ; if ( os . contains ( "Windows" ) ) { return windows ( ) ; } else if ( os . contains ( "OS X" ) ) { return osX ( ) ; } else { return unix ( ) ; } } | Returns a default configuration appropriate to the current operating system . |
25,979 | public static ParameterizedType getSuperParameterizedType ( Type type , Class < ? > superClass ) { if ( type instanceof Class < ? > || type instanceof ParameterizedType ) { outer : while ( type != null && type != Object . class ) { Class < ? > rawType ; if ( type instanceof Class < ? > ) { rawType = ( Class < ? > ) type ; } else { ParameterizedType parameterizedType = ( ParameterizedType ) type ; rawType = getRawClass ( parameterizedType ) ; if ( rawType == superClass ) { return parameterizedType ; } if ( superClass . isInterface ( ) ) { for ( Type interfaceType : rawType . getGenericInterfaces ( ) ) { Class < ? > interfaceClass = interfaceType instanceof Class < ? > ? ( Class < ? > ) interfaceType : getRawClass ( ( ParameterizedType ) interfaceType ) ; if ( superClass . isAssignableFrom ( interfaceClass ) ) { type = interfaceType ; continue outer ; } } } } type = rawType . getGenericSuperclass ( ) ; } } return null ; } | Returns the parameterized type that is or extends the given type that matches the given super class . |
25,980 | public static boolean isAssignableToOrFrom ( Class < ? > classToCheck , Class < ? > anotherClass ) { return classToCheck . isAssignableFrom ( anotherClass ) || anotherClass . isAssignableFrom ( classToCheck ) ; } | Returns whether a class is either assignable to or from another class . |
25,981 | public static < T > T newInstance ( Class < T > clazz ) { try { return clazz . newInstance ( ) ; } catch ( IllegalAccessException e ) { throw handleExceptionForNewInstance ( e , clazz ) ; } catch ( InstantiationException e ) { throw handleExceptionForNewInstance ( e , clazz ) ; } } | Creates a new instance of the given class by invoking its default constructor . |
25,982 | public static Type getBound ( WildcardType wildcardType ) { Type [ ] lowerBounds = wildcardType . getLowerBounds ( ) ; if ( lowerBounds . length != 0 ) { return lowerBounds [ 0 ] ; } return wildcardType . getUpperBounds ( ) [ 0 ] ; } | Returns the only bound of the given wildcard type . |
25,983 | public static Type resolveTypeVariable ( List < Type > context , TypeVariable < ? > typeVariable ) { GenericDeclaration genericDeclaration = typeVariable . getGenericDeclaration ( ) ; if ( genericDeclaration instanceof Class < ? > ) { Class < ? > rawGenericDeclaration = ( Class < ? > ) genericDeclaration ; int contextIndex = context . size ( ) ; ParameterizedType parameterizedType = null ; while ( parameterizedType == null && -- contextIndex >= 0 ) { parameterizedType = getSuperParameterizedType ( context . get ( contextIndex ) , rawGenericDeclaration ) ; } if ( parameterizedType != null ) { TypeVariable < ? > [ ] typeParameters = genericDeclaration . getTypeParameters ( ) ; int index = 0 ; for ( ; index < typeParameters . length ; index ++ ) { TypeVariable < ? > typeParameter = typeParameters [ index ] ; if ( typeParameter . equals ( typeVariable ) ) { break ; } } Type result = parameterizedType . getActualTypeArguments ( ) [ index ] ; if ( result instanceof TypeVariable < ? > ) { Type resolve = resolveTypeVariable ( context , ( TypeVariable < ? > ) result ) ; if ( resolve != null ) { return resolve ; } } return result ; } } return null ; } | Resolves the actual type of the given type variable that comes from a field type based on the given context list . |
25,984 | @ SuppressWarnings ( "unchecked" ) public static < T > Iterable < T > iterableOf ( final Object value ) { if ( value instanceof Iterable < ? > ) { return ( Iterable < T > ) value ; } Class < ? > valueClass = value . getClass ( ) ; Preconditions . checkArgument ( valueClass . isArray ( ) , "not an array or Iterable: %s" , valueClass ) ; Class < ? > subClass = valueClass . getComponentType ( ) ; if ( ! subClass . isPrimitive ( ) ) { return Arrays . < T > asList ( ( T [ ] ) value ) ; } return new Iterable < T > ( ) { public Iterator < T > iterator ( ) { return new Iterator < T > ( ) { final int length = Array . getLength ( value ) ; int index = 0 ; public boolean hasNext ( ) { return index < length ; } public T next ( ) { if ( ! hasNext ( ) ) { throw new NoSuchElementException ( ) ; } return ( T ) Array . get ( value , index ++ ) ; } public void remove ( ) { throw new UnsupportedOperationException ( ) ; } } ; } } ; } | Returns an iterable for an input iterable or array value . |
25,985 | public static SSLContext initSslContext ( SSLContext sslContext , KeyStore trustStore , TrustManagerFactory trustManagerFactory ) throws GeneralSecurityException { trustManagerFactory . init ( trustStore ) ; sslContext . init ( null , trustManagerFactory . getTrustManagers ( ) , null ) ; return sslContext ; } | Initializes the SSL context to the trust managers supplied by the trust manager factory for the given trust store . |
25,986 | public static byte [ ] decodeBase64 ( String base64String ) { try { return BaseEncoding . base64 ( ) . decode ( base64String ) ; } catch ( IllegalArgumentException e ) { if ( e . getCause ( ) instanceof DecodingException ) { return BaseEncoding . base64Url ( ) . decode ( base64String ) ; } throw e ; } } | Decodes a Base64 String into octets . Note that this method handles both URL - safe and non - URL - safe base 64 encoded strings . |
25,987 | static HttpParams newDefaultHttpParams ( ) { HttpParams params = new BasicHttpParams ( ) ; HttpConnectionParams . setStaleCheckingEnabled ( params , false ) ; HttpConnectionParams . setSocketBufferSize ( params , 8192 ) ; ConnManagerParams . setMaxTotalConnections ( params , 200 ) ; ConnManagerParams . setMaxConnectionsPerRoute ( params , new ConnPerRouteBean ( 20 ) ) ; return params ; } | Returns a new instance of the default HTTP parameters we use . |
25,988 | public T parseFeed ( ) throws IOException , XmlPullParserException { boolean close = true ; try { this . feedParsed = true ; T result = Types . newInstance ( feedClass ) ; Xml . parseElement ( parser , result , namespaceDictionary , Atom . StopAtAtomEntry . INSTANCE ) ; close = false ; return result ; } finally { if ( close ) { close ( ) ; } } } | Parse the feed and return a new parsed instance of the feed type . This method can be skipped if all you want are the items . |
25,989 | public final < T > T parseAndClose ( Class < T > destinationClass ) throws IOException { return parseAndClose ( destinationClass , null ) ; } | Parse a JSON object array or value into a new instance of the given destination class and then closes the parser . |
25,990 | public final String skipToKey ( Set < String > keysToFind ) throws IOException { JsonToken curToken = startParsingObjectOrArray ( ) ; while ( curToken == JsonToken . FIELD_NAME ) { String key = getText ( ) ; nextToken ( ) ; if ( keysToFind . contains ( key ) ) { return key ; } skipChildren ( ) ; curToken = nextToken ( ) ; } return null ; } | Skips the values of all keys in the current object until it finds one of the given keys . |
25,991 | private JsonToken startParsingObjectOrArray ( ) throws IOException { JsonToken currentToken = startParsing ( ) ; switch ( currentToken ) { case START_OBJECT : currentToken = nextToken ( ) ; Preconditions . checkArgument ( currentToken == JsonToken . FIELD_NAME || currentToken == JsonToken . END_OBJECT , currentToken ) ; break ; case START_ARRAY : currentToken = nextToken ( ) ; break ; default : break ; } return currentToken ; } | Starts parsing an object or array by making sure the parser points to an object field name first array value or end of object or array . |
25,992 | private void parse ( ArrayList < Type > context , Object destination , CustomizeJsonParser customizeParser ) throws IOException { if ( destination instanceof GenericJson ) { ( ( GenericJson ) destination ) . setFactory ( getFactory ( ) ) ; } JsonToken curToken = startParsingObjectOrArray ( ) ; Class < ? > destinationClass = destination . getClass ( ) ; ClassInfo classInfo = ClassInfo . of ( destinationClass ) ; boolean isGenericData = GenericData . class . isAssignableFrom ( destinationClass ) ; if ( ! isGenericData && Map . class . isAssignableFrom ( destinationClass ) ) { @ SuppressWarnings ( "unchecked" ) Map < String , Object > destinationMap = ( Map < String , Object > ) destination ; parseMap ( null , destinationMap , Types . getMapValueParameter ( destinationClass ) , context , customizeParser ) ; return ; } while ( curToken == JsonToken . FIELD_NAME ) { String key = getText ( ) ; nextToken ( ) ; if ( customizeParser != null && customizeParser . stopAt ( destination , key ) ) { return ; } FieldInfo fieldInfo = classInfo . getFieldInfo ( key ) ; if ( fieldInfo != null ) { if ( fieldInfo . isFinal ( ) && ! fieldInfo . isPrimitive ( ) ) { throw new IllegalArgumentException ( "final array/object fields are not supported" ) ; } Field field = fieldInfo . getField ( ) ; int contextSize = context . size ( ) ; context . add ( field . getGenericType ( ) ) ; Object fieldValue = parseValue ( field , fieldInfo . getGenericType ( ) , context , destination , customizeParser , true ) ; context . remove ( contextSize ) ; fieldInfo . setValue ( destination , fieldValue ) ; } else if ( isGenericData ) { GenericData object = ( GenericData ) destination ; object . set ( key , parseValue ( null , null , context , destination , customizeParser , true ) ) ; } else { if ( customizeParser != null ) { customizeParser . handleUnrecognizedKey ( destination , key ) ; } skipChildren ( ) ; } curToken = nextToken ( ) ; } } | Parses the next field from the given JSON parser into the given destination object . |
25,993 | private < T > void parseArray ( Field fieldContext , Collection < T > destinationCollection , Type destinationItemType , ArrayList < Type > context , CustomizeJsonParser customizeParser ) throws IOException { JsonToken curToken = startParsingObjectOrArray ( ) ; while ( curToken != JsonToken . END_ARRAY ) { @ SuppressWarnings ( "unchecked" ) T parsedValue = ( T ) parseValue ( fieldContext , destinationItemType , context , destinationCollection , customizeParser , true ) ; destinationCollection . add ( parsedValue ) ; curToken = nextToken ( ) ; } } | Parse a JSON Array from the given JSON parser into the given destination collection optionally using the given parser customizer . |
25,994 | private void parseMap ( Field fieldContext , Map < String , Object > destinationMap , Type valueType , ArrayList < Type > context , CustomizeJsonParser customizeParser ) throws IOException { JsonToken curToken = startParsingObjectOrArray ( ) ; while ( curToken == JsonToken . FIELD_NAME ) { String key = getText ( ) ; nextToken ( ) ; if ( customizeParser != null && customizeParser . stopAt ( destinationMap , key ) ) { return ; } Object value = parseValue ( fieldContext , valueType , context , destinationMap , customizeParser , true ) ; destinationMap . put ( key , value ) ; curToken = nextToken ( ) ; } } | Parse a JSON Object from the given JSON parser into the given destination map optionally using the given parser customizer . |
25,995 | public static < T , E > AtomFeedParser < T , E > create ( HttpResponse response , XmlNamespaceDictionary namespaceDictionary , Class < T > feedClass , Class < E > entryClass ) throws IOException , XmlPullParserException { InputStream content = response . getContent ( ) ; try { Atom . checkContentType ( response . getContentType ( ) ) ; XmlPullParser parser = Xml . createParser ( ) ; parser . setInput ( content , null ) ; AtomFeedParser < T , E > result = new AtomFeedParser < T , E > ( namespaceDictionary , parser , content , feedClass , entryClass ) ; content = null ; return result ; } finally { if ( content != null ) { content . close ( ) ; } } } | Parses the given HTTP response using the given feed class and entry class . |
25,996 | public void setValues ( ) { for ( Map . Entry < String , ArrayValueMap . ArrayValue > entry : keyMap . entrySet ( ) ) { @ SuppressWarnings ( "unchecked" ) Map < String , Object > destinationMap = ( Map < String , Object > ) destination ; destinationMap . put ( entry . getKey ( ) , entry . getValue ( ) . toArray ( ) ) ; } for ( Map . Entry < Field , ArrayValueMap . ArrayValue > entry : fieldMap . entrySet ( ) ) { FieldInfo . setFieldValue ( entry . getKey ( ) , destination , entry . getValue ( ) . toArray ( ) ) ; } } | Sets the fields of the given object using the values collected during parsing of the object s fields . |
25,997 | public void put ( Field field , Class < ? > arrayComponentType , Object value ) { ArrayValueMap . ArrayValue arrayValue = fieldMap . get ( field ) ; if ( arrayValue == null ) { arrayValue = new ArrayValue ( arrayComponentType ) ; fieldMap . put ( field , arrayValue ) ; } arrayValue . addValue ( arrayComponentType , value ) ; } | Puts an additional value for the given field accumulating values on repeated calls on the same field . |
25,998 | public void put ( String keyName , Class < ? > arrayComponentType , Object value ) { ArrayValueMap . ArrayValue arrayValue = keyMap . get ( keyName ) ; if ( arrayValue == null ) { arrayValue = new ArrayValue ( arrayComponentType ) ; keyMap . put ( keyName , arrayValue ) ; } arrayValue . addValue ( arrayComponentType , value ) ; } | Puts an additional value for the given key name accumulating values on repeated calls on the same key name . |
25,999 | public boolean handleRedirect ( int statusCode , HttpHeaders responseHeaders ) { String redirectLocation = responseHeaders . getLocation ( ) ; if ( getFollowRedirects ( ) && HttpStatusCodes . isRedirect ( statusCode ) && redirectLocation != null ) { setUrl ( new GenericUrl ( url . toURL ( redirectLocation ) ) ) ; if ( statusCode == HttpStatusCodes . STATUS_CODE_SEE_OTHER ) { setRequestMethod ( HttpMethods . GET ) ; setContent ( null ) ; } headers . setAuthorization ( ( String ) null ) ; headers . setIfMatch ( ( String ) null ) ; headers . setIfNoneMatch ( ( String ) null ) ; headers . setIfModifiedSince ( ( String ) null ) ; headers . setIfUnmodifiedSince ( ( String ) null ) ; headers . setIfRange ( ( String ) null ) ; return true ; } return false ; } | Sets up this request object to handle the necessary redirect if redirects are turned on it is a redirect status code and the header has a location . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.