Advertisement
kuza2010

[libaums]: FileSystemService class

Jan 21st, 2020
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.37 KB | None | 0 0
  1. @Override
  2. public synchronized InputStream getInputStream(UsbMassStorageDevice device, FileItem fileItem)
  3.         throws USBException, IOException {
  4.  
  5.     Timber.tag(TAG).d("getInputStream: open stream %s ...", fileItem.getPath());
  6.     FileSystem fs = getFs(device);
  7.     UsbFile rootDir = fs.getRootDirectory();
  8.  
  9.     // getRelativePath return /folder/file.txt for path /Usb_prefix/folder/file.txt
  10.     UsbFile srcFile = rootDir.search(getRelativePath(fs, fileItem.getPath()));
  11.     if (srcFile == null)
  12.         throw new USBException(USBErrorCode.FILE_NOT_FOUND);
  13.  
  14.     return UsbFileStreamFactory.createBufferedInputStream(srcFile, fs);
  15. }
  16.  
  17. @Override
  18. public synchronized OutputStream getOutputStream(UsbMassStorageDevice device, FileItem fileItem)
  19.         throws IOException, USBException {
  20.  
  21.     Timber.tag(TAG).d("getOutputStream: open stream %s ...", fileItem.getPath());
  22.     FileSystem fs = getFs(device);
  23.     UsbFile rootDir = fs.getRootDirectory();
  24.  
  25.     UsbFile srcFile = rootDir.search(getRelativePath(fs, fileItem.getPath()));
  26.     if (srcFile != null)
  27.         throw new USBException(USBErrorCode.FILE_EXISTS);
  28.  
  29.     //create parent folder for srcFile
  30.     UsbFile srcFileParentFolder = mkDirs(device, constructParentFileItem(fileItem));
  31.     srcFile = srcFileParentFolder.createFile(fileItem.getName());
  32.  
  33.     return UsbFileStreamFactory.createBufferedOutputStream(srcFile, fs);
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement