If you think the Android project voicesmith listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Voicesmith <http://voicesmith.jurihock.de/>
*//www.java2s.com
* Copyright (c) 2011-2014 Juergen Hock
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/package de.jurihock.voicesmith.io.file;
import java.io.DataInputStream;
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteOrder;
import android.content.Context;
import android.os.Environment;
import de.jurihock.voicesmith.Utils;
publicfinalclass FileInDevice extends FileDevice
{
private DataInputStream input = null;
public FileInDevice(Context context, String fileName)
throws IOException
{
this(context, fileName, ByteOrder.nativeOrder());
}
public FileInDevice(Context context, String fileName, ByteOrder fileEncoding)
throws IOException
{
super(context);
if (!Environment.MEDIA_MOUNTED.equals(
Environment.getExternalStorageState()))
{
thrownew IOException("Unable to mount external storage!");
}
File fileDir = Environment.getExternalStorageDirectory();
File file = newFile(fileDir, fileName);
this.setFilePath(file.getAbsolutePath());
this.setFileEncoding(fileEncoding);
input = new DataInputStream(new FileInputStream(file));
}
@Override
publicint read(short[] buffer, int offset, int count)
{
if (count == 0) return 0;
int result = 0;
finalboolean swapBytes =
this.getFileEncoding() != ByteOrder.nativeOrder();
for (int i = 0; i < count; i++)
{
try
{
short value = input.readShort();
if (swapBytes) value = swapBytes(value);
buffer[i + offset] = value;
result++;
}
catch (EOFException eof)
{
buffer[i + offset] = 0;
result++;
}
catch (IOException exception)
{
new Utils(context).log(exception);
}
}
return result;
}
@Override
publicvoid dispose()
{
if (input != null)
{
try
{
input.close();
}
catch (IOException exception)
{
new Utils(context).log(exception);
}
finally
{
input = null;
}
}
}
}