Examples of CannotWriteException


Examples of entagged.audioformats.exceptions.CannotWriteException

  public void deleteTag(AudioFile f) throws CannotWriteException {
    String ext = Utils.getExtension(f);

    Object afw = writers.get(ext);
    if (afw == null)
      throw new CannotWriteException(
          "No Deleter associated to this extension: " + ext);

    ((AudioFileWriter) afw).delete(f);
  }
View Full Code Here

Examples of entagged.audioformats.exceptions.CannotWriteException

  public void writeFile(AudioFile f) throws CannotWriteException {
    String ext = Utils.getExtension(f);

    Object afw = writers.get(ext);
    if (afw == null)
      throw new CannotWriteException(
          "No Writer associated to this extension: " + ext);

    ((AudioFileWriter) afw).write(f);
  }
View Full Code Here

Examples of entagged.audioformats.exceptions.CannotWriteException

            }
            createModifiedCopy(new GenericTag(), header, raf, tempRaf, true);
        } catch (IOException ioe) {
            throw ioe;
        } catch (Exception cre) {
            throw new CannotWriteException(
                    "Cannot modify tag because exception occured:\n   "
                            + cre.getMessage());
        }
    }
View Full Code Here

Examples of entagged.audioformats.exceptions.CannotWriteException

            }
            createModifiedCopy(tag, header, raf, rafTemp, false);
        } catch (IOException ioe) {
            throw ioe;
        } catch (Exception cre) {
            throw new CannotWriteException(
                    "Cannot modify tag because exception occured:\n   "
                            + cre.getMessage());
        }
    }
View Full Code Here

Examples of entagged.audioformats.exceptions.CannotWriteException

   * @exception CannotWriteException
   *                if anything went wrong
   */
  public synchronized void delete(AudioFile f) throws CannotWriteException {
    if (!f.canWrite())
      throw new CannotWriteException("Can't write to file \""
          + f.getAbsolutePath() + "\"");

    if (f.length() <= 150)
      throw new CannotWriteException("Less than 150 byte \""
          + f.getAbsolutePath() + "\"");

    RandomAccessFile raf = null;
    RandomAccessFile rafTemp = null;
    File tempF = null;
    // Will be set to true on VetoException, causing the finally block to
    // discard
    // the tempfile.
    boolean revert = false;
    try {

      tempF = File.createTempFile("entagged", ".tmp", f.getParentFile());
      rafTemp = new RandomAccessFile(tempF, "rw");
      raf = new RandomAccessFile(f, "rw");
      raf.seek(0);
      rafTemp.seek(0);

      try {
        if (this.modificationListener != null) {
          this.modificationListener.fileWillBeModified(f, true);
        }
        deleteTag(raf, rafTemp);
        if (this.modificationListener != null) {
          this.modificationListener.fileModified(f, tempF);
        }
      } catch (ModifyVetoException veto) {
        throw new CannotWriteException(veto);
      }

    } catch (Exception e) {
      revert = true;
      throw new CannotWriteException("\"" + f.getAbsolutePath() + "\" :"
          + e, e);
    } finally {
      // will be set to the remaining file.
      File result = f;
      try {
View Full Code Here

Examples of entagged.audioformats.exceptions.CannotWriteException

      delete(af);
      return;
    }

    if (!af.canWrite())
      throw new CannotWriteException("Can't write to file \""
          + af.getAbsolutePath() + "\"");

    if (af.length() <= 150)
      throw new CannotWriteException("Less than 150 byte \""
          + af.getAbsolutePath() + "\"");

    RandomAccessFile raf = null;
    RandomAccessFile rafTemp = null;
    File tempF = null;
    // Will be set to true in exception block to not replace original file.
    boolean cannotWrite = false;
    try {

      tempF = File.createTempFile("entagged", ".tmp", af.getParentFile());
      rafTemp = new RandomAccessFile(tempF, "rw");
      raf = new RandomAccessFile(af, "rw");
      raf.seek(0);
      rafTemp.seek(0);
      try {
        if (this.modificationListener != null) {
          this.modificationListener.fileWillBeModified(af, false);
        }
        writeTag(af.getTag(), raf, rafTemp);
        if (this.modificationListener != null) {
          this.modificationListener.fileModified(af, tempF);
        }
      } catch (ModifyVetoException veto) {
        throw new CannotWriteException(veto);
      }
    } catch (Exception e) {
      cannotWrite = true;
      throw new CannotWriteException("\"" + af.getAbsolutePath() + "\" :"
          + e);
    } finally {
      File result = af;
      try {
        if (raf != null)
View Full Code Here

Examples of org.jaudiotagger.audio.exceptions.CannotWriteException

        bbTemp.rewind();
        rafTemp.getChannel().write(bbTemp);
        //Check we have written all the data
        //TODO could we do any other checks to check data written correctly ?
        if ((raf.length() - startAudio) != (rafTemp.length() - startAudioWritten)) {
            throw new CannotWriteException("File written counts don't match, file not written");
        }
    }
View Full Code Here

Examples of org.jaudiotagger.audio.exceptions.CannotWriteException

            //Calculate Checksum
            calculateChecksumOverPage(nextPageHeaderBuffer);
            rafTemp.getChannel().write(nextPageHeaderBuffer);
        }
        if ((raf.length() - startAudio) != (rafTemp.length() - startAudioWritten)) {
            throw new CannotWriteException("File written counts don't match, file not written");
        }
    }
View Full Code Here

Examples of org.jaudiotagger.audio.exceptions.CannotWriteException

        //Read existing data
        FlacStreamReader flacStream = new FlacStreamReader(raf);
        try {
            flacStream.findStream();
        } catch (CannotReadException cre) {
            throw new CannotWriteException(cre.getMessage());
        }

        boolean isLastBlock = false;
        while (!isLastBlock) {
            MetadataBlockHeader mbh = MetadataBlockHeader.readHeader(raf);
View Full Code Here

Examples of org.jaudiotagger.audio.exceptions.CannotWriteException

     * @param af The file to process
     * @throws CannotWriteException if anything went wrong
     */
    public synchronized void delete(AudioFile af) throws CannotReadException, CannotWriteException {
        if (!af.getFile().canWrite()) {
            throw new CannotWriteException(ErrorMessage.GENERAL_DELETE_FAILED.getMsg(af.getFile().getPath()));
        }

        if (af.getFile().length() <= MINIMUM_FILESIZE) {
            throw new CannotWriteException(ErrorMessage.GENERAL_DELETE_FAILED.getMsg(af.getFile().getPath()));
        }

        RandomAccessFile raf = null;
        RandomAccessFile rafTemp = null;
        File tempF = null;

        //Will be set to true on VetoException, causing the finally block to discard the tempfile.
        boolean revert = false;

        try {

            tempF = File.createTempFile(af.getFile().getName().replace('.', '_'), TEMP_FILENAME_SUFFIX, af.getFile().getParentFile());
            rafTemp = new RandomAccessFile(tempF, WRITE_MODE);
            raf = new RandomAccessFile(af.getFile(), WRITE_MODE);
            raf.seek(0);
            rafTemp.seek(0);

            try {
                if (this.modificationListener != null) {
                    this.modificationListener.fileWillBeModified(af, true);
                }
                deleteTag(raf, rafTemp);
                if (this.modificationListener != null) {
                    this.modificationListener.fileModified(af, tempF);
                }
            } catch (ModifyVetoException veto) {
                throw new CannotWriteException(veto);
            }

        } catch (Exception e) {
            revert = true;
            throw new CannotWriteException("\"" + af.getFile().getAbsolutePath() + "\" :" + e, e);
        } finally {
            // will be set to the remaining file.
            File result = af.getFile();
            try {
                if (raf != null) {
                    raf.close();
                }
                if (rafTemp != null) {
                    rafTemp.close();
                }

                if (tempF.length() > 0 && !revert) {
                    boolean deleteResult = af.getFile().delete();
                    if (deleteResult == false) {
                            //logger.warning(ErrorMessage.GENERAL_WRITE_FAILED_TO_DELETE_ORIGINAL_FILE.getMsg(af.getFile().getPath(), tempF.getPath()));
                        throw new CannotWriteException(ErrorMessage.GENERAL_WRITE_FAILED_TO_DELETE_ORIGINAL_FILE.getMsg(af.getFile().getPath(), tempF.getPath()));
                    }
                    boolean renameResult = tempF.renameTo(af.getFile());
                    if (renameResult == false) {
                            //logger.warning(ErrorMessage.GENERAL_WRITE_FAILED_TO_RENAME_TO_ORIGINAL_FILE.getMsg(af.getFile().getPath(), tempF.getPath()));
                        throw new CannotWriteException(ErrorMessage.GENERAL_WRITE_FAILED_TO_RENAME_TO_ORIGINAL_FILE.getMsg(af.getFile().getPath(), tempF.getPath()));
                    }
                    result = tempF;

                    //If still exists we can now delete
                    if (tempF.exists()) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.