当前位置: 首页>>代码示例>>Java>>正文


Java NoExternalStorageException类代码示例

本文整理汇总了Java中org.thoughtcrime.securesms.database.NoExternalStorageException的典型用法代码示例。如果您正苦于以下问题:Java NoExternalStorageException类的具体用法?Java NoExternalStorageException怎么用?Java NoExternalStorageException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


NoExternalStorageException类属于org.thoughtcrime.securesms.database包,在下文中一共展示了NoExternalStorageException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: saveAttachment

import org.thoughtcrime.securesms.database.NoExternalStorageException; //导入依赖的package包/类
private @Nullable File saveAttachment(Context context, MasterSecret masterSecret, Attachment attachment)
    throws NoExternalStorageException, IOException
{
  String      contentType = MediaUtil.getCorrectedMimeType(attachment.contentType);
  String         fileName = attachment.fileName;

  if (fileName == null) fileName = generateOutputFileName(contentType, attachment.date);
  fileName = sanitizeOutputFileName(fileName);

  File    outputDirectory = createOutputDirectoryFromContentType(contentType);
  File          mediaFile = createOutputFile(outputDirectory, fileName);
  InputStream inputStream = PartAuthority.getAttachmentStream(context, masterSecret, attachment.uri);

  if (inputStream == null) {
    return null;
  }

  OutputStream outputStream = new FileOutputStream(mediaFile);
  Util.copy(inputStream, outputStream);

  MediaScannerConnection.scanFile(context, new String[]{mediaFile.getAbsolutePath()},
                                  new String[]{contentType}, null);

  return mediaFile.getParentFile();
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:26,代码来源:SaveAttachmentTask.java

示例2: createOutputDirectoryFromContentType

import org.thoughtcrime.securesms.database.NoExternalStorageException; //导入依赖的package包/类
private File createOutputDirectoryFromContentType(@NonNull String contentType)
    throws NoExternalStorageException
{
  File outputDirectory;

  if (contentType.startsWith("video/")) {
    outputDirectory = StorageUtil.getVideoDir();
  } else if (contentType.startsWith("audio/")) {
    outputDirectory = StorageUtil.getAudioDir();
  } else if (contentType.startsWith("image/")) {
    outputDirectory = StorageUtil.getImageDir();
  } else {
    outputDirectory = StorageUtil.getDownloadDir();
  }

  if (!outputDirectory.mkdirs()) Log.w(TAG, "mkdirs() returned false, attempting to continue");
  return outputDirectory;
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:19,代码来源:SaveAttachmentTask.java

示例3: testDoInBackground_emptyImageAttachmentWithFileNameIsCorrectlySavedWithIndex

import org.thoughtcrime.securesms.database.NoExternalStorageException; //导入依赖的package包/类
public void testDoInBackground_emptyImageAttachmentWithFileNameIsCorrectlySavedWithIndex()
        throws IOException, NoExternalStorageException
{
  final String name = "testImageThatShouldNotAlreadyExist";
  final String extension = "png";
  final String outputFileName = name + "." + extension;
  final String contentType = "image/png";
  final File outputDir = StorageUtil.getImageDir();
  final ArrayList<File> testFiles = populateWithTestFiles(name, extension, outputDir);
  final File expectedOutputFile = generateOutputFileForKnownFilename(name, extension, outputDir);
  testFiles.add(expectedOutputFile);

  verifyAttachmentSavedCorrectly(outputFileName, contentType, outputDir, expectedOutputFile);

  for (File tmpFile : testFiles) {
    assertTrue(tmpFile.delete());
  }
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:19,代码来源:SaveAttachmentTaskTest.java

示例4: doInBackground

import org.thoughtcrime.securesms.database.NoExternalStorageException; //导入依赖的package包/类
@Override
protected Pair<Integer, File> doInBackground(SaveAttachmentTask.Attachment... attachments) {
  if (attachments == null || attachments.length == 0) {
    throw new AssertionError("must pass in at least one attachment");
  }

  try {
    Context      context      = contextReference.get();
    MasterSecret masterSecret = masterSecretReference.get();
    File         directory    = null;

    if (!StorageUtil.canWriteInSignalStorageDir()) {
      return new Pair<>(WRITE_ACCESS_FAILURE, null);
    }

    if (context == null) {
      return new Pair<>(FAILURE, null);
    }

    for (Attachment attachment : attachments) {
      if (attachment != null) {
        directory = saveAttachment(context, masterSecret, attachment);
        if (directory == null) return new Pair<>(FAILURE, null);
      }
    }

    if (attachments.length > 1) return new Pair<>(SUCCESS, null);
    else                        return new Pair<>(SUCCESS, directory);
  } catch (NoExternalStorageException|IOException ioe) {
    Log.w(TAG, ioe);
    return new Pair<>(FAILURE, null);
  }
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:34,代码来源:SaveAttachmentTask.java

示例5: getSignalStorageDir

import org.thoughtcrime.securesms.database.NoExternalStorageException; //导入依赖的package包/类
private static File getSignalStorageDir() throws NoExternalStorageException {
  final File storage = Environment.getExternalStorageDirectory();

  if (!storage.canWrite()) {
    throw new NoExternalStorageException();
  }

  return storage;
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:10,代码来源:StorageUtil.java

示例6: canWriteInSignalStorageDir

import org.thoughtcrime.securesms.database.NoExternalStorageException; //导入依赖的package包/类
public static boolean canWriteInSignalStorageDir() {
  File storage;

  try {
    storage = getSignalStorageDir();
  } catch (NoExternalStorageException e) {
    return false;
  }

  return storage.canWrite();
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:12,代码来源:StorageUtil.java

示例7: testDoInBackground_emptyImageAttachmentWithFileNameIsCorrectlySaved

import org.thoughtcrime.securesms.database.NoExternalStorageException; //导入依赖的package包/类
public void testDoInBackground_emptyImageAttachmentWithFileNameIsCorrectlySaved()
        throws IOException, NoExternalStorageException
{
  final String name = "testImageThatShouldNotAlreadyExist";
  final String extension = "png";
  final String outputFileName = name + "." + extension;
  final String contentType = "image/png";
  final File outputDir = StorageUtil.getImageDir();
  final File expectedOutputFile = generateOutputFileForKnownFilename(name, extension, outputDir);

  verifyAttachmentSavedCorrectly(outputFileName, contentType, outputDir, expectedOutputFile);

  assertTrue(expectedOutputFile.delete());
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:15,代码来源:SaveAttachmentTaskTest.java

示例8: testDoInBackground_emptyImageAttachmentWithoutFileNameIsCorrectlySaved

import org.thoughtcrime.securesms.database.NoExternalStorageException; //导入依赖的package包/类
public void testDoInBackground_emptyImageAttachmentWithoutFileNameIsCorrectlySaved()
        throws IOException, NoExternalStorageException
{
  final String extension = "png";
  final String contentType = "image/png";
  final File outputDir = StorageUtil.getImageDir();
  final File expectedOutputFile = generateOutputFileForUnknownFilename(extension, TEST_TIMESTAMP, outputDir);

  verifyAttachmentSavedCorrectly(null, contentType, outputDir, expectedOutputFile);

  assertTrue(expectedOutputFile.delete());
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:13,代码来源:SaveAttachmentTaskTest.java

示例9: testDoInBackground_emptyImageAttachmentWithoutFileNameNorExtensionIsCorrectlySaved

import org.thoughtcrime.securesms.database.NoExternalStorageException; //导入依赖的package包/类
public void testDoInBackground_emptyImageAttachmentWithoutFileNameNorExtensionIsCorrectlySaved()
        throws IOException, NoExternalStorageException
{
  final String extension = "attach";
  final String contentType = "image/";
  final File outputDir = StorageUtil.getImageDir();
  final File expectedOutputFile = generateOutputFileForUnknownFilename(extension, TEST_TIMESTAMP, outputDir);

  verifyAttachmentSavedCorrectly(null, contentType, outputDir, expectedOutputFile);

  assertTrue(expectedOutputFile.delete());
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:13,代码来源:SaveAttachmentTaskTest.java

示例10: testDoInBackground_emptyAudioAttachmentWithFileNameIsCorrectlySaved

import org.thoughtcrime.securesms.database.NoExternalStorageException; //导入依赖的package包/类
public void testDoInBackground_emptyAudioAttachmentWithFileNameIsCorrectlySaved()
        throws IOException, NoExternalStorageException
{
  final String name = "testAudioThatShouldNotAlreadyExist";
  final String extension = "mp3";
  final String outputFileName = name + "." + extension;
  final String contentType = "audio/";
  final File outputDir = StorageUtil.getAudioDir();
  final File expectedOutputFile = generateOutputFileForKnownFilename(name, extension, outputDir);

  verifyAttachmentSavedCorrectly(outputFileName, contentType, outputDir, expectedOutputFile);

  assertTrue(expectedOutputFile.delete());
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:15,代码来源:SaveAttachmentTaskTest.java

示例11: testDoInBackground_emptyVideoAttachmentWithFileNameIsCorrectlySaved

import org.thoughtcrime.securesms.database.NoExternalStorageException; //导入依赖的package包/类
public void testDoInBackground_emptyVideoAttachmentWithFileNameIsCorrectlySaved()
        throws IOException, NoExternalStorageException
{
  final String name = "testVideoThatShouldNotAlreadyExist";
  final String extension = "mp4";
  final String outputFileName = name + "." + extension;
  final String contentType = "video/";
  final File outputDir = StorageUtil.getVideoDir();
  final File expectedOutputFile = generateOutputFileForKnownFilename(name, extension, outputDir);

  verifyAttachmentSavedCorrectly(outputFileName, contentType, outputDir, expectedOutputFile);

  assertTrue(expectedOutputFile.delete());
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:15,代码来源:SaveAttachmentTaskTest.java

示例12: testDoInBackground_emptyUnknownAttachmentWithFileNameIsCorrectlySaved

import org.thoughtcrime.securesms.database.NoExternalStorageException; //导入依赖的package包/类
public void testDoInBackground_emptyUnknownAttachmentWithFileNameIsCorrectlySaved()
        throws IOException, NoExternalStorageException
{
  final String name = "testFileThatShouldNotAlreadyExist";
  final String extension = "rand";
  final String outputFileName = name + "." + extension;
  final String contentType = "somethingweird/";
  final File outputDir = StorageUtil.getDownloadDir();
  final File expectedOutputFile = generateOutputFileForKnownFilename(name, extension, outputDir);

  verifyAttachmentSavedCorrectly(outputFileName, contentType, outputDir, expectedOutputFile);

  assertTrue(expectedOutputFile.delete());
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:15,代码来源:SaveAttachmentTaskTest.java

示例13: getBackupDir

import org.thoughtcrime.securesms.database.NoExternalStorageException; //导入依赖的package包/类
public static File getBackupDir() throws NoExternalStorageException {
  return getSignalStorageDir();
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:4,代码来源:StorageUtil.java

示例14: getVideoDir

import org.thoughtcrime.securesms.database.NoExternalStorageException; //导入依赖的package包/类
public static File getVideoDir() throws NoExternalStorageException {
  return new File(getSignalStorageDir(), Environment.DIRECTORY_MOVIES);
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:4,代码来源:StorageUtil.java

示例15: getAudioDir

import org.thoughtcrime.securesms.database.NoExternalStorageException; //导入依赖的package包/类
public static File getAudioDir() throws NoExternalStorageException {
  return new File(getSignalStorageDir(), Environment.DIRECTORY_MUSIC);
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:4,代码来源:StorageUtil.java


注:本文中的org.thoughtcrime.securesms.database.NoExternalStorageException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。