本文整理汇总了Java中org.jaudiotagger.audio.exceptions.CannotWriteException类的典型用法代码示例。如果您正苦于以下问题:Java CannotWriteException类的具体用法?Java CannotWriteException怎么用?Java CannotWriteException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CannotWriteException类属于org.jaudiotagger.audio.exceptions包,在下文中一共展示了CannotWriteException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: delete
import org.jaudiotagger.audio.exceptions.CannotWriteException; //导入依赖的package包/类
/**
* Delete given {@link Tag} from file.
*
* @param tag tag, must be instance of {@link AiffTag}
* @param file
* @throws java.io.IOException
* @throws org.jaudiotagger.audio.exceptions.CannotWriteException
*/
public void delete(final Tag tag, File file) throws CannotWriteException {
try {
FileChannel fc = new FileOutputStream(file.getAbsolutePath(), false).getChannel();
logger.severe(file.getAbsolutePath() + " Deleting tag from file");
final AiffTag existingTag = getExistingMetadata(file);
if (existingTag.isExistingId3Tag() && existingTag.getID3Tag().getStartLocationInFile() != null) {
ChunkHeader chunkHeader = seekToStartOfMetadata(fc, existingTag, file.getAbsolutePath());
if (isAtEndOfFileAllowingForPaddingByte(existingTag, fc)) {
logger.severe(file.getAbsolutePath() + " Setting new length to:" + (existingTag.getStartLocationInFileOfId3Chunk()));
fc.truncate(existingTag.getStartLocationInFileOfId3Chunk());
} else {
logger.severe(file.getAbsolutePath() + " Deleting tag chunk");
deleteTagChunk(fc, existingTag, chunkHeader, file.getAbsolutePath());
}
rewriteRiffHeaderSize(fc);
}
logger.severe(file.getAbsolutePath() + " Deleted tag from file");
} catch (IOException ioe) {
throw new CannotWriteException(file.getAbsolutePath() + ":" + ioe.getMessage());
}
}
示例2: writeInfoChunk
import org.jaudiotagger.audio.exceptions.CannotWriteException; //导入依赖的package包/类
/**
* Write Info chunk to current location which is last chunk of file
*
* @param fc
* @param existingInfoTag
* @param newTagBuffer
* @throws CannotWriteException
* @throws IOException
*/
private void writeInfoChunk(FileChannel fc, final WavInfoTag existingInfoTag, ByteBuffer newTagBuffer)
throws CannotWriteException, IOException {
long newInfoTagSize = newTagBuffer.limit();
//We have enough existing space in chunk so just keep existing chunk size
if (existingInfoTag.getSizeOfTag() >= newInfoTagSize) {
writeInfoDataToFile(fc, newTagBuffer, existingInfoTag.getSizeOfTag());
//To ensure old data from previous tag are erased
if (existingInfoTag.getSizeOfTag() > newInfoTagSize) {
writePaddingToFile(fc, (int) (existingInfoTag.getSizeOfTag() - newInfoTagSize));
}
}
//New tag is larger so set chunk size to accommodate it
else {
writeInfoDataToFile(fc, newTagBuffer, newInfoTagSize);
}
}
示例3: saveActiveExisting
import org.jaudiotagger.audio.exceptions.CannotWriteException; //导入依赖的package包/类
/**
* Save Active chunk and existing chunks even if not the active chunk
*
* @param wavTag
* @param fc
* @param existingTag
* @throws CannotWriteException
* @throws IOException
*/
private void saveActiveExisting(WavTag wavTag, FileChannel fc, final WavTag existingTag)
throws CannotWriteException, IOException {
if (wavTag.getActiveTag() instanceof WavInfoTag) {
if (existingTag.isExistingId3Tag()) {
saveBoth(wavTag, fc, existingTag);
} else {
saveActive(wavTag, fc, existingTag);
}
} else {
if (existingTag.isExistingInfoTag()) {
saveBoth(wavTag, fc, existingTag);
} else {
saveActive(wavTag, fc, existingTag);
}
}
}
示例4: delete
import org.jaudiotagger.audio.exceptions.CannotWriteException; //导入依赖的package包/类
public void delete(RandomAccessFile raf, RandomAccessFile tempRaf) throws IOException, CannotReadException, CannotWriteException
{
try
{
reader.read(raf);
}
catch (CannotReadException e)
{
write(VorbisCommentTag.createNewTag(), raf, tempRaf);
return;
}
VorbisCommentTag emptyTag = VorbisCommentTag.createNewTag();
//Go back to start of file
raf.seek(0);
write(emptyTag, raf, tempRaf);
}
示例5: replaceSecondPageAndRenumberPageSeqs
import org.jaudiotagger.audio.exceptions.CannotWriteException; //导入依赖的package包/类
/**
* Previously comment and/or setup header was on a number of pages now can just replace this page fitting all
* on 2nd page, and renumber subsequent sequence pages
*
* @param originalHeaderSizes
* @param newCommentLength
* @param newSecondPageLength
* @param secondPageHeader
* @param newComment
* @param raf
* @param rafTemp
* @throws IOException
* @throws org.jaudiotagger.audio.exceptions.CannotReadException
* @throws org.jaudiotagger.audio.exceptions.CannotWriteException
*/
private void replaceSecondPageAndRenumberPageSeqs(OggVorbisTagReader.OggVorbisHeaderSizes originalHeaderSizes, int newCommentLength, int newSecondPageLength, OggPageHeader secondPageHeader, ByteBuffer newComment, RandomAccessFile raf, RandomAccessFile rafTemp) throws IOException, CannotReadException, CannotWriteException
{
logger.fine("WriteOgg Type 2");
ByteBuffer secondPageBuffer = startCreateBasicSecondPage(originalHeaderSizes, newCommentLength, newSecondPageLength, secondPageHeader, newComment);
//Add setup header and packets
int pageSequence = secondPageHeader.getPageSequence();
byte[] setupHeaderData = reader.convertToVorbisSetupHeaderPacketAndAdditionalPackets(originalHeaderSizes.getSetupHeaderStartPosition(), raf);
logger.finest(setupHeaderData.length + ":" + secondPageBuffer.position() + ":" + secondPageBuffer.capacity());
secondPageBuffer.put(setupHeaderData);
calculateChecksumOverPage(secondPageBuffer);
rafTemp.getChannel().write(secondPageBuffer);
writeRemainingPages(pageSequence, raf, rafTemp);
}
示例6: writeNewMetadataLargerButCanUseFreeAtom
import org.jaudiotagger.audio.exceptions.CannotWriteException; //导入依赖的package包/类
/**
* We can fit the metadata in under the meta item just by using some of the padding available in the {@code free}
* atom under the {@code meta} atom need to take of the side of free header otherwise might end up with
* solution where can fit in data, but can't fit in free atom header.
*
* @param fileReadChannel
* @param fileWriteChannel
* @param neroTagsHeader
* @param sizeOfExistingMetaLevelFreeAtom
* @param newIlstData
* @param additionalSpaceRequiredForMetadata
* @throws IOException
* @throws CannotWriteException
*/
private void writeNewMetadataLargerButCanUseFreeAtom(FileChannel fileReadChannel, FileChannel fileWriteChannel, Mp4BoxHeader ilstHeader, Mp4BoxHeader neroTagsHeader, int sizeOfExistingMetaLevelFreeAtom, ByteBuffer newIlstData, int additionalSpaceRequiredForMetadata) throws IOException, CannotWriteException
{
int newFreeSize = sizeOfExistingMetaLevelFreeAtom - (additionalSpaceRequiredForMetadata);
logger.config("Writing:Option 5;Larger Size can use meta free atom need extra:" + newFreeSize + "bytes");
writeDataUptoIncludingIlst(fileReadChannel, fileWriteChannel, ilstHeader, newIlstData);
//Create an amended smaller freeBaos atom and write it to file
Mp4FreeBox newFreeBox = new Mp4FreeBox(newFreeSize - Mp4BoxHeader.HEADER_LENGTH);
fileWriteChannel.write(newFreeBox.getHeader().getHeaderData());
fileWriteChannel.write(newFreeBox.getData());
//Skip over the read channel old free atom
fileReadChannel.position(fileReadChannel.position() + sizeOfExistingMetaLevelFreeAtom);
writeDataAfterIlst(fileReadChannel, fileWriteChannel, neroTagsHeader);
}
示例7: writeDataInChunks
import org.jaudiotagger.audio.exceptions.CannotWriteException; //导入依赖的package包/类
/**
* Write the remainder of data in read channel to write channel data in {@link TagOptionSingleton#getWriteChunkSize()}
* chunks, needed if writing large amounts of data.
*
* @param fileReadChannel
* @param fileWriteChannel
* @throws IOException
* @throws CannotWriteException
*/
private void writeDataInChunks(FileChannel fileReadChannel, FileChannel fileWriteChannel) throws IOException, CannotWriteException
{
long amountToBeWritten = fileReadChannel.size() - fileReadChannel.position();
long written = 0;
long chunksize = TagOptionSingleton.getInstance().getWriteChunkSize();
long count = amountToBeWritten / chunksize;
long mod = amountToBeWritten % chunksize;
for (int i = 0; i < count; i++)
{
written += fileWriteChannel.transferFrom(fileReadChannel, fileWriteChannel.position(), chunksize);
fileWriteChannel.position(fileWriteChannel.position() + chunksize);
}
if(mod > 0)
{
written += fileWriteChannel.transferFrom(fileReadChannel, fileWriteChannel.position(), mod);
if (written != amountToBeWritten)
{
throw new CannotWriteException("Was meant to write " + amountToBeWritten + " bytes but only written " + written + " bytes");
}
}
}
示例8: delete
import org.jaudiotagger.audio.exceptions.CannotWriteException; //导入依赖的package包/类
/**
* Delete the tag (if any) present in the given file
*
* @param af The file to process
*
* @throws CannotWriteException if anything went wrong
* @throws org.jaudiotagger.audio.exceptions.CannotReadException
*/
@Override
public void delete(AudioFile af) throws CannotReadException, CannotWriteException
{
File file = af.getFile();
if (TagOptionSingleton.getInstance().isCheckIsWritable() && !file.canWrite())
{
throw new CannotWriteException(ErrorMessage.GENERAL_DELETE_FAILED
.getMsg(file.getAbsolutePath()));
}
if (af.getFile().length() <= MINIMUM_FILESIZE)
{
throw new CannotWriteException(ErrorMessage.GENERAL_DELETE_FAILED_BECAUSE_FILE_IS_TOO_SMALL
.getMsg(file));
}
deleteTag(af.getTag(), file);
}
示例9: write
import org.jaudiotagger.audio.exceptions.CannotWriteException; //导入依赖的package包/类
/**
* Replace with new tag
*
* @param af The file we want to process
* @throws CannotWriteException
*/
@Override
public void write(AudioFile af) throws CannotWriteException
{
File file = af.getFile();
if (TagOptionSingleton.getInstance().isCheckIsWritable() && !file.canWrite())
{
logger.severe(ErrorMessage.GENERAL_WRITE_FAILED.getMsg(af.getFile()
.getPath()));
throw new CannotWriteException(ErrorMessage.GENERAL_WRITE_FAILED_TO_OPEN_FILE_FOR_EDITING
.getMsg(file.getAbsolutePath()));
}
if (af.getFile().length() <= MINIMUM_FILESIZE)
{
throw new CannotWriteException(ErrorMessage.GENERAL_WRITE_FAILED_BECAUSE_FILE_IS_TOO_SMALL
.getMsg(file));
}
writeTag(af.getTag(), file);
}
示例10: precheckWrite
import org.jaudiotagger.audio.exceptions.CannotWriteException; //导入依赖的package包/类
/**
* Prechecks before normal write
* <p/>
* <ul>
* <li>If the tag is actually empty, remove the tag</li>
* <li>if the file is not writable, throw exception
* <li>
* <li>If the file is too small to be a valid file, throw exception
* <li>
* </ul>
*
* @param af
* @throws CannotWriteException
*/
private void precheckWrite(AudioFile af) throws CannotWriteException {
// Preliminary checks
try {
if (af.getTag().isEmpty()) {
delete(af);
return;
}
} catch (CannotReadException re) {
throw new CannotWriteException(ErrorMessage.GENERAL_WRITE_FAILED.getMsg(af.getFile().getPath()));
}
File file = af.getFile();
if (TagOptionSingleton.getInstance().isCheckIsWritable() && !file.canWrite()) {
logger.severe(ErrorMessage.GENERAL_WRITE_FAILED.getMsg(af.getFile().getPath()));
throw new CannotWriteException(ErrorMessage.GENERAL_WRITE_FAILED_TO_OPEN_FILE_FOR_EDITING.getMsg(file.getAbsolutePath()));
}
if (af.getFile().length() <= MINIMUM_FILESIZE) {
logger.severe(ErrorMessage.GENERAL_WRITE_FAILED_BECAUSE_FILE_IS_TOO_SMALL.getMsg(file.getAbsolutePath()));
throw new CannotWriteException(ErrorMessage.GENERAL_WRITE_FAILED_BECAUSE_FILE_IS_TOO_SMALL.getMsg(file.getAbsolutePath()));
}
}
示例11: deleteTag
import org.jaudiotagger.audio.exceptions.CannotWriteException; //导入依赖的package包/类
/**
* Delete Metadata tag
*
* @param tag
* @param file
* @throws CannotWriteException
* @throws IOException
*/
@Override
protected void deleteTag(Tag tag, File file) throws CannotWriteException {
try {
FileChannel fc = new FileOutputStream(file.getAbsolutePath(), false).getChannel();
DsdChunk dsd = DsdChunk.readChunk(Utils.readFileDataIntoBufferLE(fc, DsdChunk.DSD_HEADER_LENGTH));
if (dsd != null) {
if (dsd.getMetadataOffset() > 0) {
fc.position(dsd.getMetadataOffset());
ID3Chunk id3Chunk = ID3Chunk.readChunk(Utils.readFileDataIntoBufferLE(fc, (int) (fc.size() - fc.position())));
if (id3Chunk != null) {
fc.truncate(dsd.getMetadataOffset());
//set correct value for fileLength and zero offset
dsd.setMetadataOffset(0);
dsd.setFileLength(fc.size());
fc.position(0);
fc.write(dsd.write());
}
} else {
//Do Nothing;
}
}
} catch (IOException ioe) {
throw new CannotWriteException(file.getAbsolutePath() + ":" + ioe.getMessage());
}
}
示例12: writeFile
import org.jaudiotagger.audio.exceptions.CannotWriteException; //导入依赖的package包/类
/**
*
* Write the tag contained in the audioFile in the actual file on the disk.
*
*
* @param f The AudioFile to be written
* @param targetPath a file path, without an extension, which provides a "save as". If null, then normal "save" function
* @throws NoWritePermissionsException if the file could not be written to due to file permissions
* @throws CannotWriteException If the file could not be written/accessed, the extension
* wasn't recognized, or other IO error occurred.
*/
public void writeFile(AudioFile f, String targetPath) throws CannotWriteException
{
String ext = f.getExt();
if (targetPath != null && !targetPath.isEmpty())
{
final File destination = new File(targetPath + "." + ext);
try
{
Utils.copyThrowsOnException(f.getFile(), destination);
f.setFile(destination);
} catch (IOException e) {
throw new CannotWriteException("Error While Copying" + e.getMessage());
}
}
AudioFileWriter afw = writers.get(ext);
if (afw == null)
{
throw new CannotWriteException(ErrorMessage.NO_WRITER_FOR_THIS_FORMAT.getMsg(ext));
}
afw.write(f);
}
示例13: insertLyrics
import org.jaudiotagger.audio.exceptions.CannotWriteException; //导入依赖的package包/类
/**
* Insert Lyrics
*
* @param path
* @param lyrics
* @return
*/
public static boolean insertLyrics(String path, String lyrics) {
File f = new File(path);
if (f.exists()) {
try {
AudioFile audioFile = AudioFileIO.read(f);
if (audioFile == null) {
return false;
}
TagOptionSingleton.getInstance().setAndroid(true);
Tag tag = audioFile.getTag();
if (tag == null) {
return false;
}
tag.deleteField(FieldKey.LYRICS);
tag.setField(FieldKey.LYRICS, lyrics);
audioFile.setTag(tag);
AudioFileIO.write(audioFile);
return true;
} catch (CannotReadException | CannotWriteException | InvalidAudioFrameException | TagException | IOException | ReadOnlyFileException e) {
e.printStackTrace();
}
}
return false;
}
示例14: writeDataInChunks
import org.jaudiotagger.audio.exceptions.CannotWriteException; //导入依赖的package包/类
/**
* #385 Write data in chunks, needed if writing large amounts of data
*
* @param fileReadChannel
* @param fileWriteChannel
* @throws IOException
* @throws CannotWriteException
*/
private void writeDataInChunks(FileChannel fileReadChannel, FileChannel fileWriteChannel)
throws IOException, CannotWriteException {
long amountToBeWritten = fileReadChannel.size() - fileReadChannel.position();
long written = 0;
long chunksize = TagOptionSingleton.getInstance().getWriteChunkSize();
long count = amountToBeWritten / chunksize;
long mod = amountToBeWritten % chunksize;
for (int i = 0; i < count; i++) {
written += fileWriteChannel.transferFrom(fileReadChannel, fileWriteChannel.position(), chunksize);
fileWriteChannel.position(fileWriteChannel.position() + chunksize);
}
written += fileWriteChannel.transferFrom(fileReadChannel, fileWriteChannel.position(), mod);
if (written != amountToBeWritten) {
throw new CannotWriteException("Was meant to write " + amountToBeWritten + " bytes but only written " + written + " bytes");
}
}
示例15: persistThroughFile
import org.jaudiotagger.audio.exceptions.CannotWriteException; //导入依赖的package包/类
/**
* Writes changes in tags directly into file and closes activity.
* Call this if you're absolutely sure everything is right with file and tag.
*/
private void persistThroughFile() {
try {
AudioFileIO.write(mAudioFile);
Toast.makeText(this, R.string.file_written_successfully, Toast.LENGTH_SHORT).show();
// update media database
File persisted = mAudioFile.getFile();
MediaScannerConnection.scanFile(this, new String[]{persisted.getAbsolutePath()}, null, null);
} catch (CannotWriteException e) {
Log.e(LOG_TAG,
String.format(getString(R.string.error_audio_file), mAudioFile.getFile().getPath()), e);
Toast.makeText(this,
String.format(getString(R.string.error_audio_file) + ", %s",
mAudioFile.getFile().getPath(),
e.getLocalizedMessage()),
Toast.LENGTH_LONG).show();
}
}