Bytes array into a wav file
hi every1, any1 can help plz, how to write bytes from an audio file (which is stored in an array) back into a wave file thanx
Hi,
it is something like this:
byte[] myByteArray; //your bytearray
AudioFormat myAudioFormat; //neccessary to interpret the bytes in the right manner
long mySampleFrameLength; //how long your audiodata is
AudioInputStream ais = new AudioInputStream(new ByteArrayInputStream(myByteArray), myAudioFormat, mySampleFrameLength);
AudioSystem.write(ais, AudioFileFormat.Type.WAVE, new File("myWaveFile.wav"));
Similar Messages
-
How can I convert an array into a .wav file?
I have an array of points that I need converted and written into a .wav file. Any help?
Indeed there is!
Look at the attached vi....that's about all there is to it!
Good Luck..
Eric
Eric P. Nichols
P.O. Box 56235
North Pole, AK 99705
Attachments:
ARRAY_TO_WAVE.vi 17 KB -
How to change the image into byte and byte array into image
now i am developing one project. i want change the image into byte array and then byte array into image.
FileInputStream is = new FileInputStream(file);
byte[] result = IOUtils.toByteArray(is);
with apache common IO lib -
How do I convert an audio link into a wav file?
how do I convert an audio link into a wav file with my Imac?
A PC user showed me to right click an audio link where it asked if it wanted to save the link as a Wav file?
I saw this done in front of me. How do I do it with my Mac ?This is how to do it in itunes http://support.apple.com/kb/ht1550
If I view the song in finder, all that i have to do is press command-i and it opens a window. In the section where you view the name and extension I took off the extension (.mp3 in my case) and replaced it with .wav -
Write arrays into a text file in different columns at different times
Hi,
I have a problem write data into a text file. I want to write 4 1D arrays into a text file. The problem is that I need to write it at different time and in different column (in other word, not only append the arrays).
Do you have an idea to solve my problem?
Thank youA file is long a linear string of data (text). In order ro insert columns, you need to rewrite the entire file, because colums are interlaced over the entire lenght of the file.
So:
read file into 2D array
insert columns using array operations
write resulting 2D array to file again.
(Only if your colums are guaranteed to be fixed width AND you know the final number of colums, you could write the missing columns as spaces and then overwrite later. Still, it will be painful and inefficient, because column data are not adjacent in the file.)
LabVIEW Champion . Do more with less code and in less time . -
Hi all,
I am currently doing a heart sound analyzer project. I acquired signal using NI USB 6008 continuosly. My program is able to saved the acquired signal into a wave file. But when I browse open the saved file, the output waveform did not look the same as the acquired input signal and also the sound of the heartbeat captured cannot be heard from the loud speaker though I have saved the file as a wav file. I am not sure if the method i use to save the acquired data as a wav file is correct. I have attach the print screen of the differences of the output I have notice and the program I have created. I would be glad if anyone here is able to troubleshoot my program.
Thanks.
Attachments:
heart sound analyzer.zip 257 KBHi Brett Burger,
Thanks for your reply. For your information, I have set the sampling rate as 10000 as for the sound format, I have set the bits per sample as 16 bit, the rate as 11025 and the sound quality as mono. I tried using your method by changing the sampling rate as 8K but still my program encounter the same problem.
I wish to also create a button that is able to generate a preformatted report that contains VI documentation, data the VI returns, and report properties, such as the author, company, and number of pages only when I click on the button. I have created this in my program, but I am not sure why is it not working. Can you help troubleshoot my program. Or do you have any samples to provide me. Hope to hear from you soon.
Many thanks.
Regards,
min
Attachments:
Heart Sounds1.vi 971 KB -
hi,
I got a byte array from a file and want to turn it into a file, so i can access it thru the operating system.
byte[] lop = rs.getBytes("data");
can anyone give any help, or a good tutorial to do this.Check out the API docs for the FileOutputStream class and pay special attention to its
write(byte[]) method.
kind regards,
Jos -
Converting a byte array into int
Here's my problem, I've read my data from a server into a byte array.
the array is 12 elements in length representing three int variables.
int flag;
int query_a;
int query_b;
here's what i receive:
0 0 0 0 34 0 0 -2 21 0 0 0
how do i convert these into the int values i need.
i know the first four are for flag = 0, but how does it convert?
0000 = 0 for each byte
00000000 00000000 00000000 00000000 = 0 for each bit?
or is there a method to convert from a byte to int?Look at the ByteBuffer class (part of 1.4.1) - before that, you would have had to manually build your integers using left shift and & operator (not that big of a deal, really).
Be sure you know the "Endian"-ness of the platform you are reading data from though, otherwise, your ints will not be what you expect!
- K -
How do i convert a garage band recording into a wav file?
I made a recording in Garage Band that I need upload to a particular website, but it only accepts wav files.
Supported WAV formats:
- Mono is preferable to stereo, but stereo is accepted.
- 8000Hz, 16-bit, PCM, mono is the recommended format.
- 44,100Hz, 16-bit, PCM is also supported
- mp3 files are NOT supported
Does anyone know how to do this? I went on You Tube which says to send to iTunes selecting WAV, but it does not seem to be working. Any suggestions?
AndreaGB doesn't export .wav files. Sharet he file to disk as an uncompressed AIFF file, then use iTunes to convert it to .wav. (Go to iTunes' import settings and select .wav.)
-
Saving an integer array into a .txt file
hii, im only a beginner in java, so this is the only code i've learned so far for saving array elements into a file
public static void saveNames(String [] name) throws IOException
FileWriter file = new FileWriter("Example\\names.txt");
BufferedWriter out = new BufferedWriter(file);
int i = 0;
while (i < name.length)
if (name[i] != null)
out.write(name);
out.newLine();
i++;
out.flush();
out.close();
However, this is only used for string arrays; and i can't call the same method for an integer array (because it's not compatible with null)
I don't really understand this code either... since my teacher actually just gave us the code to use, and didn't really explain how it works
I have the same problem for my reading a file code as well --> it's only compatible with string
public static String [] readNames (String [] name) throws IOException
int x = 0;
int counter = 0;
String temp = "asdf";
name = new String [100];
FileReader file = new FileReader("Example\\names.txt");
BufferedReader in = new BufferedReader(file);
int i = 0;
while (i < array.length && temp != null) // while the end of file is not reached
temp = in.readLine();
if (temp != null)
name[i] = temp; // saves temp into the array
else
name[i] = "";
i++;
in.close(); // close the file
return name;
Could someone suggest a way to save elements from an integer array to a file, and read integer elements of that file?
Or if it's possible, replace null with a similar variable (function?), that is suitable for the integer array (i can't use temp != 0 because some of my elements might be 0)
Thanks so much!!!!!because it's not compatible with nullI think it should be okay to just remove the null condition check since there are no null elements in a primitive array when writing.
Use Integer.parseInt() [http://java.sun.com/javase/6/docs/api/java/lang/Integer.html] to convert the String into an Integer when you read it back and use Integer.toString() to be able to write it as a String. -
So, I search the binary matlab file format('*.mat').
Title:
Moving Data Between MATLAB® and LabVIEW
Problem:
How can I share data between LabVIEW and the MATLAB environment?
Solution:
MATLAB users can move data between the
MATLAB environment and LabVIEW, you have several options. Prior to
LabVIEW 5.1, the only way to transfer data between these two
environments was to use the Save and Load functions. Those are discussed herein.
Beginning
in LabVIEW 8.0, MathScipt was introduced. MathScript is an integrated
part of LabVIEW that you can use to combine intuitive graphical
dataflow programming with math-oriented textual programming. See the
attached links below for more information on MathScript.
Beginning
in LabVIEW 5.1, the MATLAB script node was introduced into the LabVIEW
programming environment. The MATLAB script node makes ActiveX calls to
the MATLAB software from within LabVIEW. This requires that both MATLAB
be installed on the same machine and that a valid license is obtained.
More information on the MATLAB script node can be found in the attached
KB's.
For all versions of LabVIEW, this data transfer can be
performed by saving the data in a file using the MATLAB software and
reading it directly from LabVIEW, or vice versa. In the MATLAB
environment, the command "save" allows you to save the data in
binary format (*.mat) or ASCII format. You also have an option of
saving it in ASCII format using a tab delimiter between data points and
the command "load" allows you to read in the data.
ASCII Format
Complete the following steps to import or export data between LabVIEW and the MATLAB environment using an ASCII file format.
From the MATLAB environment to LabVIEW
To save a vector or a matrix X in tab-delimited ASCII format, enter the following in the command window or m-script file in the MATLAB environment:
>>SAVE filename X -ascii -double -tabs
This creates a file named filename containing data X in tab-delimited ASCII format.
Import the file into LabVIEW using the Read From Spreadsheet File VI located on the Functions»File I/O palette.
From LabVIEW to the MATLAB environment
To export a matrix X from LabVIEW to the MATLAB environment, first save the data in ASCII format in LabVIEW using the Write To Spreadsheet File VI on the Functions » File I/O palette.
Enter the following in the command window of the MATLAB environment, or in the m-script file:
>> LOAD filename
This reads the data into the MATLAB environment.
Binary Format
Complete the following steps to import or export data between LabVIEW and the MATLAB environment.
From the MATLAB environment to LabVIEW
As mentioned above, LabVIEW does not save multiple variables to one
data with extra manipulation, and will not be discussed here.
Therefore, the only way of sending the data from the MATLAB environment
to LabVIEW without tampering with the MAT binary file structure is
using the ASCII format. Also, please bear in mind that you need to have
one file for one variable.
From LabVIEW to the MATLAB environment
Because
the MATLAB software saves data in its own binary format, the "MAT"
file, binary LabVIEW data must be converted to this format prior to
transferring the data. The attached examples can be used to save
LabVIEW data in the MATLAB software format. The convenience of the .MAT
file format is that more than one variable can be saved in the same
file. The example shows saving seven variables to .MAT format; the
example can be modified for any number of variables.
Once this data is saved from LabVIEW, it can be read into the MATLAB environment, using the following command:
>>LOAD filename
The Who
command can then be used to display all the seven variable names, and
you can display the content of them by entering the variable names at
the command prompt as usual.
MATLAB® is a
registered trademark of The MathWorks, Inc. Other product and company
names listed are trademarks and trade names of their respective
companies.
| Michael K | Project Manager | LabVIEW R&D | National Instruments | -
Playing a wav file (byte array) using JMF
Hi,
I want to play a wav file in form of a byte array using JMF. I have 2 classes, MyDataSource and MyPullBufferStream. MyDataSource class is inherited from PullStreamDataSource, and MyPullBufferStream is derived from PullBufferStream. When I run the following piece of code, I got an error saying "EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x7c9108b2, pid=3800, tid=1111". Any idea what might be the problem? Thanks.
File file = new File(filename);
byte[] data = FileUtils.readFileToByteArray(file);
MyDataSource ds = new MyDataSource(data);
ds.connect();
try
player = Manager.createPlayer(ds);
catch (NoPlayerException e)
e.printStackTrace();
if (player != null)
this.filename = filename;
JMFrame jmframe = new JMFrame(player, filename);
desktop.add(jmframe);
import java.io.IOException;
import javax.media.Time;
import javax.media.protocol.PullBufferDataSource;
import javax.media.protocol.PullBufferStream;
public class MyDataSource extends PullBufferDataSource
protected Object[] controls = new Object[0];
protected boolean started = false;
protected String contentType = "raw";
protected boolean connected = false;
protected Time duration = DURATION_UNKNOWN;
protected PullBufferStream[] streams = null;
protected PullBufferStream stream = null;
protected final byte[] data;
public MyDataSource(final byte[] data)
this.data = data;
public String getContentType()
if (!connected)
System.err.println("Error: DataSource not connected");
return null;
return contentType;
public void connect() throws IOException
if (connected)
return;
stream = new MyPullBufferStream(data);
streams = new MyPullBufferStream[1];
streams[0] = this.stream;
connected = true;
public void disconnect()
try
if (started)
stop();
catch (IOException e)
connected = false;
public void start() throws IOException
// we need to throw error if connect() has not been called
if (!connected)
throw new java.lang.Error(
"DataSource must be connected before it can be started");
if (started)
return;
started = true;
public void stop() throws IOException
if (!connected || !started)
return;
started = false;
public Object[] getControls()
return controls;
public Object getControl(String controlType)
try
Class cls = Class.forName(controlType);
Object cs[] = getControls();
for (int i = 0; i < cs.length; i++)
if (cls.isInstance(cs))
return cs[i];
return null;
catch (Exception e)
// no such controlType or such control
return null;
public Time getDuration()
return duration;
public PullBufferStream[] getStreams()
if (streams == null)
streams = new MyPullBufferStream[1];
stream = streams[0] = new MyPullBufferStream(data);
return streams;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import javax.media.Buffer;
import javax.media.Control;
import javax.media.Format;
import javax.media.format.AudioFormat;
import javax.media.protocol.ContentDescriptor;
import javax.media.protocol.PullBufferStream;
public class MyPullBufferStream implements PullBufferStream
private static final int BLOCK_SIZE = 500;
protected final ContentDescriptor cd = new ContentDescriptor(ContentDescriptor.RAW);
protected AudioFormat audioFormat = new AudioFormat(AudioFormat.GSM_MS, 8000.0, 8, 1,
Format.NOT_SPECIFIED, AudioFormat.SIGNED, 8, Format.NOT_SPECIFIED,
Format.byteArray);
private int seqNo = 0;
private final byte[] data;
private final ByteArrayInputStream bais;
protected Control[] controls = new Control[0];
public MyPullBufferStream(final byte[] data)
this.data = data;
bais = new ByteArrayInputStream(data);
public Format getFormat()
return audioFormat;
public void read(Buffer buffer) throws IOException
synchronized (this)
Object outdata = buffer.getData();
if (outdata == null || !(outdata.getClass() == Format.byteArray)
|| ((byte[]) outdata).length < BLOCK_SIZE)
outdata = new byte[BLOCK_SIZE];
buffer.setData(outdata);
byte[] data = (byte[])buffer.getData();
int bytes = bais.read(data);
buffer.setData(data);
buffer.setFormat(audioFormat);
buffer.setTimeStamp(System.currentTimeMillis());
buffer.setSequenceNumber(seqNo);
buffer.setLength(BLOCK_SIZE);
buffer.setFlags(0);
buffer.setHeader(null);
seqNo++;
public boolean willReadBlock()
return bais.available() > 0;
public boolean endOfStream()
return willReadBlock();
public ContentDescriptor getContentDescriptor()
return cd;
public long getContentLength()
return (long)data.length;
public Object getControl(String controlType)
try
Class cls = Class.forName(controlType);
Object cs[] = getControls();
for (int i = 0; i < cs.length; i++)
if (cls.isInstance(cs[i]))
return cs[i];
return null;
catch (Exception e)
// no such controlType or such control
return null;
public Object[] getControls()
return controls;Here's some additional information. After making the following changes to MyPullBufferStream class, I can play a wav file with gsm-ms encoding with one issue: the wav file is played many times faster.
protected AudioFormat audioFormat = new AudioFormat(AudioFormat.GSM, 8000.0, 8, 1,
Format.NOT_SPECIFIED, AudioFormat.SIGNED, 8, Format.NOT_SPECIFIED,
Format.byteArray);
// put the entire byte array into the buffer in one shot instead of
// giving a portion of it multiple times
public void read(Buffer buffer) throws IOException
synchronized (this)
Object outdata = buffer.getData();
if (outdata == null || !(outdata.getClass() == Format.byteArray)
|| ((byte[]) outdata).length < BLOCK_SIZE)
outdata = new byte[BLOCK_SIZE];
buffer.setData(outdata);
buffer.setLength(this.data.length);
buffer.setOffset(0);
buffer.setFormat(audioFormat);
buffer.setData(this.data);
seqNo++;
} -
How to open a byte array of pdf into acrobat reader dynamically..
hi,
my java program is connecting to a url and downloading various file(.pdf,.xml format) into hard-disk. now the requirement is if user select "Preview" button, then file is downloaded and opened with appropriate application(acrobat reader for .pdf file) but not saved anywhere in hard-disk ...
any idea, any hint any help is welcomed..
thanks in advance..hi friends,
i got the solution. i am using one external api of adobe acrobat, through which i am able to stream pdf document in form of byte array into acrobat viewer,without writing data in any file.
so my work is done.. :) -
Byte array to base64encoder problem, cannot encode a 7.7 MB file
hey guys, so ive been trying to use the base64encoder to encode a bytearray which is then sent thru a webservice to the server to be decoded.
and as the subject of this post suggests, i have been having problems encoding a big file,
forexample i tried to upload/convert a 84KB image and it worked just fine... the trace of the string ended with a "==" which i believe means that the conversion is complete...
but when i try to upload a 7.7MB image, it is, i guess, crashing... i dont see any "==" in the string... so i guess its not working... i was wondering if there is any any type of file size limit or soemthign for the encoding...
the code i have is
import flash.events.Event;
import flash.net.FileFilter;
import flash.net.FileReference;
import flash.utils.ByteArray;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.utils.Base64Encoder;
import services.images.ImageData;
import services.images.Images;
import services.images.ReturnMessage;
// ActionScript file
public var fileRef:FileReference = new FileReference();
public var imgCollection:ArrayCollection = new ArrayCollection();
public var imgService:Images = new Images();
public var imageData:ImageData = new ImageData();
public var returnMsg:ReturnMessage = new ReturnMessage();
public function onBrowseButtonClicked(event:MouseEvent):void{
var arr:Array = [];
arr.push(new FileFilter("Images", ".gif;*.jepg;*.jpg;*.png"));
fileRef.browse(arr);
fileRef.addEventListener(Event.SELECT, fileRef_select);
fileRef.addEventListener(Event.COMPLETE, fileRef_complete);
public function fileRef_select(event:Event):void{
fileRef.load();
public function fileRef_complete(event:Event):void{
img.source = fileRef.data;
var fileByteArr:ByteArray = fileRef.data;
var b64En:Base64Encoder = new Base64Encoder();
b64En.encodeBytes(fileByteArr); //<----------------------------------------------------------
var str:String = b64En.flush(); //<----------------------------------------------------------
trace(str.length);
b64En.reset();
trace("------------------------------------ " + str + " -----------------------------");
imageData.Base64EncodedImage = str;
imageData.FileName = "nameofstring";
imgService.UploadImage(imageData);
imgService.addEventListener(FaultEvent.FAULT, servFault);
imgService.addEventListener(ResultEvent.RESULT, imgServSuccess);
public function imgServSuccess(event:ResultEvent):void{
Alert.show("i am in the result");
returnMsg = event.result as ReturnMessage;
var resultStr:String = event.result as String;
Alert.show(resultStr);
if(returnMsg.ThereWasAnError){
trace(returnMsg.ErrorMessages.getItemAt(0).toString());
public function servFault(event:FaultEvent):void{
Alert.show("2 " + event.fault.message);
Alert.show("3 " + event.fault.faultCode);
any help will be greatly appretiated!! thanks in advace!yeah i did actually... except i think i changed a LOT of code since i last posted this article...
so i dont remember where this code is exactly... lol
i have the following code now...
hope this helps
i use a a lot of webservices... so there is some of that code included in there aswell...
* This file will do the file upload. It has been suggested to me multiple times, that using a queueing system for
* file upload is not a good idea. Instead I declared a counter and used the final function to fire the next item
* in the array. this also makes canceling a routine easier.
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.net.FileReference;
import flash.net.FileReferenceList;
import flash.utils.ByteArray;
import mx.collections.ArrayCollection;
import mx.controls.*;
import mx.managers.*;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.utils.Base64Decoder;
import mx.utils.Base64Encoder;
import services.images.Images;
import valueObjects.*;
public var t:Number = 0;
public var fileRef:FileReferenceList = new FileReferenceList();
public var listCacheFiles:Array = new Array();
[Bindable] public var fileListArr:Array = new Array();
[Bindable] public var fileNames:ArrayCollection = new ArrayCollection();
[Bindable] public var arrUploadFiles:Array = new Array();
public var file:FileReference;
public var _numCurrentUpload:Number = 0;
public var imageData:valueObjects.ImageData;
public var imageService:Images = new Images();
public var saveImages:Images;
public var returnMsg:ReturnMessage = new ReturnMessage();
public var dataToSave:ImageData;
public var myCounter:int = 0;
public var numPerc:Number;
/*vars to possible delete*/
public var fileListx:ArrayCollection;
* Initiates the browse, when files are selected the selectionHandler function is called
public function initiateBrowse():void{
var filter:Array = [];
filter.push(new FileFilter("Images", ".gif;*.jepg;*.jpg;*.png"));
fileRef.addEventListener(Event.SELECT, selectionHandler);
fileRef.browse(filter);
* selection handler takes the selected files and puts them in 2 different arrays
* fileListArr contains all the file information like the image itself and the name and everything
* fileNames contains the information essential to populate the datagrid in the cropper.mxml
public function selectionHandler(event:Event):void{
//trace("selection Handler ->>");
fileRef.removeEventListener(Event.SELECT, selectionHandler);
var numSelected:int = event.target.fileList.length;
var fileList:Array = event.target.fileList;
fileListx = new ArrayCollection();
fileListx = event.target.fileList as ArrayCollection;
//var oldListLength:Number = fileListArr.length;
for each(var item:Object in fileList){
fileListArr.push(item);
fileNames.addItem({
num: fileNames.length + 1,
name: item.name,
size: formatFileSize(item.size),
status: "",
itemDetails: item
var newListLength:Number = fileListArr.length;
if(myCounter > 0)
loopList(myCounter);
else
loopList(0);
* this function starts one, new filereference for each files in the array
public function loopList(value:int):void{
//trace("looplist -->");
if(value < fileListArr.length){
_numCurrentUpload = value;
file = new FileReference();
file = FileReference(fileListArr[value]);;
file.addEventListener(Event.COMPLETE, loadImage);
file.addEventListener(ProgressEvent.PROGRESS, fileProgress);
file.load();
* This function will convert the byte array into a string, and then it sends it to the server.
public function loadImage(event:Event):void{
trace("loadImage -->");
file.removeEventListener(Event.COMPLETE, loadImage);
myCounter += 1;
var fileByteArr:ByteArray = event.target.data;
var b64En:Base64Encoder = new Base64Encoder();
b64En.encodeBytes(fileByteArr);
var str:String = b64En.flush();
imageData = new ImageData();
imageData.Base64EncodedImage = str;
imageData.FileName = event.target.name;
trace("sending -->> " + imageData.FileName);
updateStatus("Sending to server");
imageService.addEventListener(ResultEvent.RESULT, imgServSuccess);
imageService.UploadImage(imageData);
b64En.reset();
* This function will decode the information recieved back from the server.
public function imgServSuccess(event:ResultEvent):void{
trace("imgServSuccess -->");
imageService.removeEventListener(ResultEvent.RESULT, imgServSuccess);
var returnedImageId:ArrayCollection = new ArrayCollection();
returnMsg = event.result as ReturnMessage;
var returnedData:Object = event.result.Images;
var imgD:ImageData = new ImageData();
if(returnMsg.ThereWasAnError){
trace(returnMsg.ErrorMessages.getItemAt(0).toString());
else{
for each(var imgData:ImageData in returnedData){
var decoded:Base64Decoder = new Base64Decoder();
decoded.decode(imgData.Base64EncodedImage);
var byteArr:ByteArray = decoded.toByteArray();
//img.source = byteArr;
dataToSave = new ImageData();
dataToSave = returnedData[0];
listCacheFiles.push(dataToSave);
updateStatus("Item in Cache");
//uploadDetails.visible = true;
loopList(myCounter);
public var win:itemDetails;
public function itemClicking(event:Event):void{
var fileName:String = event.currentTarget.dataProvider[0].name;
for(var i:Number = 0; i < listCacheFiles.length; i++){
//var temp:ImageData = event.target as ImageData;
win = null;
win = itemDetails(PopUpManager.createPopUp(this, itemDetails, true));
win.title = "Enter Details";
PopUpManager.centerPopUp(win);
win["save"].addEventListener("click", popupClosed);
public function popupClosed(event:Event):void{
var returnedData:ImageData = new ImageData;
returnedData = win.dataToSave;
saveImgAndData(returnedData);
public function saveImgAndData(data:ImageData):void{
saveImages = new Images;
saveImages.showBusyCursor = true;
saveImages.addEventListener(ResultEvent.RESULT, savedSuccess);
saveImages.addEventListener(FaultEvent.FAULT, faultFunc);
saveImages.SaveUploadedImageInformation(data);
public function faultFunc(event:FaultEvent):void{
Alert.show(event.fault.message);
Alert.show(event.fault.faultString);
public function savedSuccess(event:ResultEvent):void{
//trace("savedSuccess -->");
var retMsg:Object = event.result.Images;
//trace("saving -->> " + retMsg[0].FileName);
updateStatus("Completed");
//loopList(myCounter);
private function formatFileSize(numSize:Number):String {
var strReturn:String;
numSize = Number(numSize / 1024);
strReturn = String(numSize.toFixed(1) + " KB");
if (numSize > 1024) {
numSize = numSize / 1024;
strReturn = String(numSize.toFixed(1) + " MB");
if (numSize > 1024) {
numSize = numSize / 1024;
strReturn = String(numSize.toFixed(1) + " GB");
return strReturn;
public function removeFiles():void{
var arrSelected:Array = displayFilesList.selectedIndices;
if(arrSelected.length >= 1){
for(var i:Number = 0; i < arrSelected.length; i++){
fileNames[Number(arrSelected[i])] = null;
var idx:int = 1;
for(var j:Number = 0; j < fileNames.length; j++){
if(fileNames[j] == null){
fileNames.removeItemAt(j);
j--;
}else{
fileNames[j].num = idx++;
if(fileNames.length > 0)
displayFilesList.selectedIndex = 0;
else
displayFilesList.selectedIndex = -1;
_numCurrentUpload--;
updateProgBar();
private function updateStatus(status:String, index:Number = -1):void{
index = _numCurrentUpload;
fileNames[index].status = status;
displayFilesList.invalidateList();
public function fileProgress(event:ProgressEvent):void{
//trace("fileProgress -->");
var numPerc:Number = Math.round((Number(event.bytesLoaded) / Number(event.bytesTotal)) * 100);
updateStatus("Uploading: " + numPerc.toString() + "%");
updateProgBar(numPerc);
var evt:ProgressEvent = new ProgressEvent("uploadProgress", false, false, event.bytesLoaded, event.bytesTotal);
dispatchEvent(evt);
public function updateProgBar(numPerc:Number = 0):void{
//trace("updateProgBar -->");
var strLabel:String = (_numCurrentUpload + 1) + "/" + fileNames.length;
progBar.label = strLabel;
progBar.setProgress(_numCurrentUpload + numPerc / 100, fileNames.length);
progBar.validateNow(); -
Reading in any file and converting to a byte array
Okay what I am trying to do is to write a program that will read in any file and convert it into a int array so that I can then manipulate the values of the int array and then re-write the file. Once I get the file into an int array I want to try and compress the data with my own algorithm as well as try to write my own encryption algorithm.
What I have been looking for is code samples that essentially read in the file as a byte array and then I have been trying to convert that byte array into an int array which I could then manipulate. So does anyone have any sample code that essentially takes a file and converts it into an int array and then converts it back into a byte array and write the file. I have found code that is close but I guess I am just too new to this. Any help would be appreciated.You can read a whole file into a byte array like this:File f = new File("somefile");
int size = (int) f.length();
byte[] contents = new byte[size];
DataInputStream in = new DataInputStream(
new BufferedInputStream(new FileInputStream(f)));
in.readFully(contents);
in.close();Note that you need to add in the proper exception handling code. You could also use RandomAccessFile instead of the DataInputStream.
Writing a byte array to a file is easier; just construct the FileOutputStream, call write on it with the byte array, and close the stream.
Maybe you are looking for
-
My external library 100 GB on a 2TB drive is taking a long time to open.
Hey there, I recently moved my library to an external drive. When I tried to load the external drive, it said it needed to repair and I let it happen overnight because it was taking a long time. Now it seems to just freeze when I try to load the ext
-
I cant get into itunes producer keep getting an error my username and password is incorrect. i have made a new one all good still same error any ideas?
-
Updated field in CO01 unrecognized
Hello, I update production scheduling profile (caufvd-sfcpf) in user exit EXIT_SAPLCOZF_003 at CO01. I added the field to HEADER_CUST and it is transferred outside. İt is a field of a subscreen. The transaction starts with the general tab and if I do
-
I have a QT movie set to fast-start that is embedded on a web page. The data rate is not too high, but high enough that people on a dial-up connection will have to wait a minute before the movie starts to play. That's fine. But, is there a way to pro
-
Ask; Snake n ladder quizz
Hello friends, I want to ask,,, anyone can help me? I'm learning to make a quiz game snakes and ladders, how to play is when before rolling the dice a player must answer the question arises, if the correct answer then the player can play dice. but if