Changing a byte in a file

hello,
I have a .dbf file that has a wrong date in its header. The month is 00 instead of 01. I want to go in the file and change the third byte (thats where it stores the month) to 01 from 00.
can I do something like this?
FileChannel fc = new FileOutputStream (new File ("hospitals.dbf")).getChannel();
ByteBuffer bb = ByteBuffer.allocate(1);
bb.put ((byte)1);
fc.write(bb,3);
fc.close();
is there a better and efficient way?
Thanks,
Pranav

Yeah it did truncate the file. I am just not getting the concept of FileChannel and MappedBufferBytes.
The randonaccessfile works just fine. Thanks a lot.

Similar Messages

  • How to replace or remove last 500 bytes of a file without rewriting all the file?

    Hi everyone,
    Usually I only ask for help when I can't find a solution for several days or weeks... And guess what? That just happen!
    So, this is what i am trying to do:
    I have a program to ZIP folder and protect them with password, then it encrypts the zip file.
    That it's working fine, until the user forgets his password.
    So, what I want to do is give the user a Recovery Password option for each ZIP file created. I can't use the Windows Registry because the idea is to be able to recover the password in any computer.So i came up with an idea...
    In simple terms, this will work like this:
    0 - Choose folder to ZIP
    1 - Ask user for recover details (date of birth, email etc)
    2 - ZIP folder with password
    3 - Encrypt ZIP file
    4 - Encrypt recover details and convert it to HEX
    5 - Add recover details (in HEX) to the end of the ZIP file (last bytes)
    6 - Add "5265636F76657244657461696C73" which is the text "RecoverDetails" in HEX
    7 - Add "504B0506000000000000000000000000000000000000" this is the final bytes of a ZIP file and will make the Operating System think that is a ZIP file (i know that will give an error when we try to open it.. the ideia is to change the
    extension later and use my software to do all the work to access this ZIP/folder again)
    So, explaining what it's here, I want to say that I managed how to do all of this so far. The point number 6 will help us to determine where the recover details are in the file, or if they actually exist because user can choose not to use them.
    In order to unlock this ZIP and extract it's contents, I need to reverse what I've done. That means, that  need to read only the last 500 bytes (or less if the file is smaller) of the ZIP and remove those extra bytes I added so the program can check
    if the user is inputing a correct password, and if so decrypt contents and extract them.
    But, if the user insert a wrong password I need to re-add those bytes with the recover details again to the ZIP file.
    The second thing is, if the user forgets his password and asks to recover it, a form will be shown asking to insert the recover detail (date of birth, email etc), so we need to reed the last 500 bytes of the ZIP, find the bytes in number 6 and remove the
    bytes before number 6, remove bytes in number 6 and number 7, and we will have the recover details to match against the user details input.
    I have all done so far with the locking process. But i need help with the unlocking.
    I am not sure if it's possible, but this what i am looking for:
    Read last 500 bytes of a file, remove the bytes with recover details and save the file. Without reading the whole file, because if we have a 1GB file that will take a very long time. Also, i don't want to "waste" hard drive space creating a new
    clone file with 1GB and then delete the original.
    And then add them back "in case user fails the password" which should be exactly the same.
    This sounds a bit confusing I know, even to me, I am writing and trying to explain this the better I can.. Also my English is not the best..
    Here it goes some code to better understanding:
    'READ LAST 500 BYTES OF ZIP FILE TO CHECK IF IT CONTAINS RECOVER DETAILS
    Dim oFileStream As New FileStream(TextBox_ZIP_to_Protect.Text & ".zip", FileMode.Open, FileAccess.Read)
    Dim oBinaryReader As New BinaryReader(oFileStream)
    Dim lBytes As Long = oFileStream.Length
    oBinaryReader.BaseStream.Position = lBytes - 500
    Dim fileData As Byte() = oBinaryReader.ReadBytes(500)
    oBinaryReader.Close()
    oFileStream.Close()
    Dim txtTemp As New System.Text.StringBuilder()
    For Each myByte As Byte In fileData
    txtTemp.Append(myByte.ToString("X2"))
    Next
    Dim RecoveryDetailsPass_Holder = txtTemp.ToString()
    'Dim Temp_2 = txtTemp.ToString()
    'RichTextBox1.Text = txtTemp.ToString()
    If txtTemp.ToString.Contains("505245434F47414653") Then
    'we have password recovery details(the numbers mean RecoverDetails in HEX)
    'next we will get rid of everything before and after of string "cut_at"
    Dim mystr As String = RecoveryDetailsPass_Holder 'RichTextBox1.Text
    Dim cut_at As String = "505245434F47414653"
    Dim x As Integer = InStr(mystr, cut_at)
    ' Dim string_before As String = mystr.Substring(0, x - 1)
    Dim string_after As String = mystr.Substring(x + cut_at.Length - 1)
    RecoveryDetailsPass_Holder = RecoveryDetailsPass_Holder.Replace(string_after.ToString, "")
    RecoveryDetailsPass_Holder = RecoveryDetailsPass_Holder.Replace("505245434F47414653", "") ' this is RecoverDetails in HEX
    RecoveryDetailsPass_Holder = RecoveryDetailsPass_Holder.Replace("504B0506000000000000000000000000000000000000", "") ' this is the bytes of an empty zip file
    'AT THIS POINT WE HAVE ONLY THE RECOVER PASSWORD DETAILS (date of birth, email etc) IN THE VARIABLE "RecoveryDetailsPass_Holder"
    '////////////////////////////////////////////////////// TO DEBUG
    'MsgBox(string_after.ToString & "505245434F47414653")
    'InputBox("", "", string_after.ToString)
    '\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ TO DEBUG
    'Temp_2 = Temp_2.Replace(RecoveryDetailsPass_Holder.ToString, "")
    Now that we have the recover details, we need to remove them from ZIP in order to the software try to unzip it with the password provided by the user on the GUI.
    If the user needs to recover the password we have the details already in RecoveryDetailsPass_Holder variable and just need to match them against user input details.
    If the user fails, we need to put the RecoveryDetailsPass_Holder back on the file.
    Any question just ask, it's a bit trick to explain i think, but please ask.
    Anyone know how to do this?
    Many thanks in advanced.
    Nothing is impossible!
    @ Portugal
    Vote if it's helpfull :)

    @ ALL
    Thank you very much for you help. I know that if I'm "playing" with bytes you should assume that I know a lot of VB.net, but I don't know that much unfortunately. I am not a beginner but I am still very fresh and I probably do stuff that work but
    probably not in the best way...
    Anyway, I will explain the idea of this little software I'm making. Once I wanted to create a program to protect folders with password, and I came up with something to change folder permissions to lock access to them, and that actually worked fine and quickly.
    However, I managed how to "crack" the protection by going to folder properties, security tab and then give permissions back to my username. So that, to me, wasn't a safer system to protect folders, also I want the ability to use passwords. So I search
    and search online for a way to do it, and someone replied (to someone with the same question as me) that the best option would be to create a zip with all contents of the folder, with password and then change the extension from .zip to .whatever and register
    the new extension .whatever on the Windows Registry, so that file will have an icon and open with my software.
    So I did...The program zips everything, change the extension and I added the encryption to avoid people changing the extension to ZIP or trying to open with 7-Zip or similar and be able to see the protected files names in the .zip/.whatever
    Answering to all of you now:
    @Armi
    "System.IO.FileStream.SetLength"
    I know I tried that but I erased the code because it didn't work for some reason, I don't remember why sorry, was long time before I created this post.
    The last code I was trying to use was this:
    ' Set the stream position to the desired location of the stream.
    Dim fileStream As IO.FileStream = _
    New IO.FileStream(TextBox_ZIP_to_Protect.Text & ".zip", IO.FileMode.Append)
    Try
    ' Set the stream (OFFSET) position to the desired location of the stream.
    fileStream.Seek(210, IO.SeekOrigin.Current)
    Dim Bytes_do_ZE As Byte() = HexStringToByteArray(Temp_2.ToString)
    'Write Characters ASCII
    For Each Byte_Do_Zeca As Byte In Bytes_do_ZE
    fileStream.WriteByte(Byte_Do_Zeca)
    Next
    Finally
    fileStream.Close()
    End Try
    and we need this:
    Private Shared Function HexStringToByteArray(ByRef strInput As String) As Byte()
    Dim length As Integer
    Dim bOutput As Byte()
    Dim c(1) As Integer
    length = strInput.Length / 2
    ReDim bOutput(length - 1)
    For i As Integer = 0 To (length - 1)
    For j As Integer = 0 To 1
    c(j) = Asc(strInput.Chars(i * 2 + j))
    If ((c(j) >= Asc("0")) And (c(j) <= Asc("9"))) Then
    c(j) = c(j) - Asc("0")
    ElseIf ((c(j) >= Asc("A")) And (c(j) <= Asc("F"))) Then
    c(j) = c(j) - Asc("A") + &HA
    ElseIf ((c(j) >= Asc("a")) And (c(j) <= Asc("f"))) Then
    c(j) = c(j) - Asc("a") + &HA
    End If
    Next j
    bOutput(i) = (c(0) * &H10 + c(1))
    Next i
    Return (bOutput)
    End Function
    That code, as I understand, is to search for the OFFSET of the bytes in the file and start to write from there... That OFFSET should be the beginning of the 500 bytes read on the code before. I got the OFFSET position "210" reading the file with
    the HEX editor "HxD - Hexeditor v1.7.7.0" but using the OFFSET won't work because every file, password, recover details and so on, are different and so the file size, changing the OFFSET I
    think.
    @Reed Kimble
    Does that sound like something which might work for you?
    Thanks for your help. That might be some solution, however it seams a bit of the same problem where we need to read the bytes again to get the recover details. But, as I said in this post, because this is meant to password protect folders, do you think that
    will apply as well?
    @Crazypennie
    Thanks for your reply.
    All this appears really weak. The user has your application since he need it to open the file .... and the code in the application contain the code to read the file without knowing the password. Therefore anyone can read your code and retrieve the
    data without the password ... if he knows VB.
    The application can only open the file if the user didn't use a password to protect the file. Because the file is encrypted and needs to be unencrypted first.
    When the application tries to open/read the file, will need to decrypt it first and then check for a password and do the validation. Also the application is with the code masked/protected which i think it might not be easy for reverse engineering.
    - You need to use a web server and a symmetric key encryption
    This a good idea, besides I don't know how to implement it. However the idea is to be able to:
    1 - Protect a folder anywhere in any Windows computer (portable app)
    2 - Recover password details (security question) in any computer, online and offline
    And I think we need a computer always connected to the Internet to use that method, right?
    @ Mr. Monkeyboy
    Thank you very much for your effort.
    I just wanted to let you know that the zip method you are using is no longer supported.
    I didn't actually knew that. Thanks for letting me know.
    Do you require the compressed encrypted files to actually be Zip files or could they just be compressed files that have nothing to do with Zip?
    No, it doesn't need to be a .zip extension. I am actually using my own extension. It starts as a Zip but then I changed to my own extension which I have registered on the Windows Registry.
    @ ALL
    Thanks again to all for trying and spending time helping me.
    By the way, I might not be able to answer or try any code during the weekend... It's easter break and family is around. Have a nice easter everyone. :)
    Nothing is impossible! Imagination is the limit!

  • Java writing out bytes from one file, reading back in again

    Hi, I'm having some trouble with bytes.
    I have one program which outputs the following bytes into a file (using Printstream.write() - I'm sure that this program is working fine):
    4 0 64 0 4 0 128 0 63 223 64 20 4 16 130 0 60 16 64 1 63 223 79 236 64 16 195 232 116 63 255 232 148 0 0 0
    I'm then reading in the bytes using the code given on this page (http://www.exampledepot.com/egs/java.io/File2ByteArray.html)
    and I get...
    4 0 64 0 4 0 -128 0 63 -33 64 20 4 16 -126 0 60 16 64 1 63 -33 79 -20 64 16 -61 -24 116 63 -1 -24 -108 0 0 0
    As you can see I now have negative numbers - I noticed that if I do 256 + (the negative number) then i get the number I originally wrote out
    I tried fixing this when I read in by doing
    bytes[i] = (byte) (256 + bytes);
    but it doesn't change anything
    how can I either change it so it reads in the bytes exactly as i wrote them out, or write a bit of code that takes the negatives and converts them to the original positives?
    thx

    Unconditional wrote:
    Integer x1 = (bytes[i] << 24) & 0xFF;
                      Integer x2 = (bytes[i+1] << 16) & 0xFF;
                      Integer x3 = (bytes[i+2] << 8) & 0xFF;
                      Integer x4 = (bytes[i+3] << 0) & 0xFF;is what I'm doing
    System.out.println("x1 " + x1 + " x2 " + x2 + " x3 " + x3 + " x4 " + x4);
    returns
    x1 0 x2 0 x3 0 x4 0
    x1 0 x2 0 x3 0 x4 4
    x1 0 x2 0 x3 0 x4 0
    x1 0 x2 0 x3 0 x4 128
    x1 0 x2 0 x3 0 x4 0
    x1 0 x2 0 x3 0 x4 63
    x1 0 x2 0 x3 0 x4 223
    x1 0 x2 0 x3 0 x4 64
    x1 0 x2 0 x3 0 x4 20What are you trying to do? Combine the bytes into an int?

  • I had renamed my user login name and assumed that there will be no change in the settings and files. When I login with the new profile name everything is gone. How can I get back all my files and settings?

    I had renamed my user login name and assumed that there will be no change in the settings and files. When I login with the new profile name everything is gone. How can I get back all my files and settings? Please help. Thanks.

    You should have asked this before you tried: Changing username or short name- User Account and Short Name- OS X- How to change user account name or home directory name.

  • Changes in server side java file not reflecting in Client side java code?

    Hi friends,
    iam using eclipse IDE, JBoss server, SWING GUI and Oracle DB
    ( looks like : SWINGGUI (Client) <--> EJB's (serverside) <---oracle )
    my problem is , when i make change in server side bean file, that changes are not reflecting in GUI programs.
    (for ex: iam adding settr and getter for a field and using that in GUI program. but its not identifying that setter or getter).
    please tell me what should i do for every change done to server side program, that should reflect / available to GUI?

    my problem is , when i make change in server side bean file, that changes are not reflecting in GUI programs.
    (for ex: iam adding settr and getter for a field and using that in GUI program. but its not identifying that setter or getter).what do you mean it's not "identifying" the methods?
    you have to call those methods you know
    are you getting NoSuchMethodError?
    please tell me what should i do for every change done to server side program, that should reflect / available to GUI?you haven't posted any code or error messages that might help us debug

  • Existing cross Reference: how to change the name of the file it refers to?

    Hi everybody,
    I am a professional translator.
    One client of mine sent me a complete FrameMaker 9 book file for translation.
    I translated the content via a CAT-Tool and now am in the process of checking if cross references and markers are ok directly into the file.
    I noticed that many cross references are linked to another file of the book. But in the process of translating each file separately, I gave them a slightly different name (I added the language at the end) so as to be able to recognise them eventually.
    Now I have this problem: I cannot find in the cross reference interface where to change the name of the file into the new one the cross reference is supposed to refer to.
    Am I right in wanting to change the file reference? If so, how do I do that?
    Or is it better to avoid this task and rename the translated file into their original names ? Would it work then?
    Thanks for your help.

    ... book file ...
    ...  each file separately, I gave  them a slightly different name (I added the language at the end) ...
    I'm guessing that you renamed the component files by means other than using the Edit > Rename File from the Book menu.
    If so, do over. Rename from the Book menu. It automatically revises all the cross-references in all the component files.
    In a Book, the only thing that's safe to rename with the file manager is the .book file itself.

  • How do I know if time machine is backing up my apple mail? I need to have copies of all of my emails, so there I have a lot of mail files. I was told that if I change computers, that the mail files will all be on time machine. Is this true? Thanks, Dave

    Is there a way to verify  if time machine is backing up my apple mail?  I was told that if I change computers, that the mail files will all be on time machine and can be easily be put on a new computer using my time machine backups.  Is this true? Thanks, Dave

    Having deleted some Mail messages by mistake, I have had to recover them from TM. I can tell you that the recovery of mail messages will be done at the mailbox level. In my case it was half of the messages in a mailbox. So I recovered the complete mailbox from TM. Then I copied the messages from the recovered mailbox back into the mailbox I use in Mail. I hope that helps.
    Please be aware that TM is a backup application and not an archival application. What that means is that if your TM drive gets full, it will get rid of older files which could be mail messages to make space for newer backups. You might want to consider archiving your mail instead of using TM if you need to maintain your mail messages for extended periods of time.
    Allan

  • Downloaded 3.6 version of firefox and it changed my favorites, quicken, other files back to 1.5 yrs ago. How do I get back the info it has erased or hidden from me???

    Question
    Today downloaded 3.6 version of firefox and it changed my favorites, quicken, other files back to 1.5 yrs ago. How do I get back the info it has erased or hidden from me???

    What do you mean by '''''"changed my favorites, quicken, other files back to 1.5 yrs ago"'''''? More detail please.
    <br />
    You have an item installed that is considered malware/spyware/adware. To see the plugins submitted with your question, click "More system details..." to the right of your original question post.
    *Ask Toolbar Plugin Stub for 32-bit Windows
    Unfortunately, it is becoming more and more common for these kinds of "extras" (toolbars, security scanners, etc.) to be added to your browser/system/desktop when adding or updating other software, some from very well-know software vendors. You must carefully read information before downloading any "free" software and be very alert during the install process for any opportunity to opt-out of "extras" being installed.
    '''<u>If you have the Ask Toolbar</u>'''<br />
    * First try to disable or uninstall the Ask Toolbar in Firefox via "Tools -> Add-ons -> Extensions". See: [[Uninstalling add-ons]]<br />
    *In some cases, you may need to uninstall the Ask Toolbar using Windows Control Panel .
    **See [http://support.mozilla.com/en-US/kb/Cannot+uninstall+an+add-on#Uninstall_from_Windows_Control_Panel Cannot uninstall an add-on - Uninstall from Windows Add/Remove Programs].
    '''<u>You '''MAY''' need to reset your homepage</u>''' if an Ask search page opens when first starting Firefox. Firefox can open multiple home pages. Home pages are separated by the "|" symbol.
    *See: http://support.mozilla.com/en-US/kb/How+to+set+the+home+page
    '''<u>You ''MAY'' need to reset a preference</u>''' if searches from the URL/location bar take you to an Ask search page.<br />
    To reset the preference related to Ask search from the URL/location bar via about:config, specifically the keyword.URL preference -<br />
    *Open a new tab or window.
    *Type '''''about:config''''' in the URL/address bar and press the Enter key
    *If you see a warning, accept it (promise to be careful)
    *Filter = keyword.url
    *Right-click on the preference below the Filter, and choose Reset
    *Restart Firefox (File > Restart Firefox)
    *See: http://kb.mozillazine.org/Keyword.URL for details.
    Also see:<br />
    * http://kb.mozillazine.org/Problematic_extensions#Ask_Toolbar
    * http://kb.mozillazine.org/Uninstalling_toolbars
    <br />
    '''Other issues that need your attention'''
    The information submitted with your question indicates that you have out of date plugins with known security and stability issues that should be updated. To see the plugins submitted with your question, click "More system details..." to the right of your original question post.
    *Adobe PDF Plug-In For Firefox and Netscape "9.3.3"
    **New Adobe Reader X (version 10) with Protected Mode just released 2010-11-19
    **See: http://www.securityweek.com/adobe-releases-acrobat-reader-x-protected-mode
    *Shockwave Flash 10.1 r82
    *Next Generation Java Plug-in 1.6.0_19 for Mozilla browsers
    **4 updates behind
    #'''Check your plugin versions''': http://www.mozilla.com/en-US/plugincheck/
    #*'''Note: plugin check page does not have information on all plugin versions'''
    #'''Update Adobe Reader (PDF plugin):'''
    #*From within your existing Adobe Reader ('''<u>if you have it already installed</u>'''):
    #**Open the Adobe Reader program from your Programs list
    #**Click Help > Check for Updates
    #**Follow the prompts for updating
    #**If this method works for you, skip the "Download complete installer" section below and proceed to "After the installation" below
    #*Download complete installer ('''if you do <u>NOT</u> have Adobe Reader installed'''):
    #**Use the links below to avoid getting the troublesome "getplus" Adobe Download Manager and other "extras" you may not want
    #**Use Firefox to download and SAVE the installer to your hard drive from the appropriate link below
    #**Click "Save to File"; save to your Desktop (so you can find it)
    #**After download completes, close Firefox
    #**Click the installer you just downloaded and allow the install to continue
    #***Note: Vista and Win7 users may need to right-click the installer and choose "Run as Administrator"
    #**'''<u>Download link</u>''': ftp://ftp.adobe.com/pub/adobe/reader/
    #***Choose your OS
    #***Choose the latest #.x version (example 9.x, for version 9)
    #***Choose the highest number version listed
    #****NOTE: 10.x is the new Adobe Reader X (Windows and Mac only as of this posting)
    #***Choose your language
    #***Download the file
    #***Windows: choose the .exe file; Mac: choose the .dmg file
    #*Using either of the links below will force you to install the "getPlus" Adobe Download Manager. Also be sure to uncheck the McAfee Scanner if you do not want the link forcibly installed on your desktop
    #**''<u>Also see Download link</u>''': http://get.adobe.com/reader/otherversions/
    #**Also see: https://support.mozilla.com/en-US/kb/Using+the+Adobe+Reader+plugin+with+Firefox (do not use the link on this page for downloading; you may get the troublesome "getplus" Adobe Download Manager (Adobe DLM) and other "extras")
    #*After the installation, start Firefox and check your version again.
    #'''Update the [[Managing the Flash plugin|Flash]] plugin''' to the latest version.
    #*Download and SAVE to your Desktop so you can find the installer later
    #*If you do not have the current version, click on the "Player Download Center" link on the "'''Download and information'''" or "'''Download Manual installers'''" below
    #*After download is complete, exit Firefox
    #*Click on the installer you just downloaded and install
    #**Windows 7 and Vista: may need to right-click the installer and choose "Run as Administrator"
    #*Start Firefox and check your version again or test the installation by going back to the download link below
    #*'''Download and information''': http://www.adobe.com/software/flash/about/
    #**Use Firefox to go to the above site to update the Firefox plugin (will also install plugin for most other browsers; except IE)
    #**Use IE to go to the above site to update the IE ActiveX
    #*'''Download Manual installers'''. Note separate links for:
    #**Plugin for Firefox and most other browsers
    #**ActiveX for IE
    #'''Update the [[Java]] plugin''' to the latest version.
    #*Download site: http://java.sun.com/javase/downloads/index.jsp (Java Platform: Download JRE)
    #*Also see "Manual Update" in this article: http://support.mozilla.com/en-US/kb/Using+the+Java+plugin+with+Firefox#Updates
    #* Removing old versions (if needed): http://www.java.com/en/download/faq/remove_olderversions.xml
    #* Remove multiple Java Console extensions (if needed): http://kb.mozillazine.org
    #*Java Test: http://www.java.com/en/download/help/testvm.xml

  • How can I change a Microsoft Word document file into a picture file?

    How can I change a Microsoft Word document file into a picture or jpeg file? I am wanting to make the image I created my background on my macbook pro.

    After I had the document image the way I wanted it, I saved it as a web page and went from there. Below are the steps starting after I did the "save as" option in Word:
    1) Select "Save As Web Page". I changed the location from documents to pictures when the window came up to save it as a web page.
    2) Go to "Finder" on you main screen, or if it's on your main toolbar at the bottom.
    3) Click on the "Pictures" tab and find the file you just re-saved as a web page. (I included "web page" or something similar in the new title so I could easily find the correct file I was looking for)
    4) Open the correct file and then "right click" on the actual image. (Use 2 fingers to do so on a Mac)
    5) Select 'Use Image As Desktop Picture", and voilà! The personally created image, or whatever it is that you wanted, is now your background.
    **One problem I encountered while doing this is that the image would show up like it was right-aligned in relation to the whole screen. The only way I could figure how to fix this was to go back to the very original document in Word, (the one before it was saved as a web page), and move everything over to the left.
    I hope this helps someone else who was as frustrated as I was with something that I thought would have been very simple to do! If you have any tips or suggestions of your own, please feel free to share. : )

  • Windows cannot verify the digital signature for the drivers required for this device. A recent hardware or software change might have installed a file that is signed incorrectly or damaged, or that might be malicious software from an unknown source. (Code

    I get this message when I check the Device manager for my Ipod
    Windows cannot verify the digital signature for the drivers required for this device. A recent hardware or software change might have installed a file that is signed incorrectly or damaged, or that might be malicious software from an unknown source. (Code 52)
    How do I resolve this I have reinstalled iTunes but it still doesn't recognise my ipod

    I reinstalled Itunes a couple of times.  I unistalled all programs that I never use, I updated all of my drivers, Windows swept my computer and found no problems.  I have a yellow causion lite when I look at the USB-port with the phone connected.  All other devices work without a problem.

  • [UCCx] Change volume of an audio file (java code)

    Hello guys,
    Thanks to the many examples I compiled on the subject, I was able to create a script that mixes 2 audio wav files into a 3rd one. Basically the goal is to mix a first audio file containing some speech with a second one containing some music, these files being encoded identically (8 bits, 8KHz, mono wav files). The resulting file must be encoded in the same format than the initial ones.
    The mixing operation is performed thanks to the MixingAudioInputStream library found online (it can be found here).
    It is not the most beautiful Java code (I am no developer), but it works:
    Document doc1 = (Document) promptFlux1;
    Document doc2 = (Document) promptFlux2;
    Document docFinal = (Document) promptFinal;
    javax.sound.sampled.AudioFormat formatAudio = null;
    java.util.List audioInputStreamList = new java.util.ArrayList();
    javax.sound.sampled.AudioInputStream ais1 = null;
    javax.sound.sampled.AudioInputStream ais2 = null;
    javax.sound.sampled.AudioInputStream aisTemp = null;
    javax.sound.sampled.AudioFileFormat formatFichierAudio = javax.sound.sampled.AudioSystem.getAudioFileFormat(new java.io.BufferedInputStream(doc1.getInputStream()));
    java.io.File fichierTemp = java.io.File.createTempFile("wav", "tmp");
    ais1 = javax.sound.sampled.AudioSystem.getAudioInputStream(doc1.getInputStream());
    formatAudio = ais1.getFormat();
    aisTemp = javax.sound.sampled.AudioSystem.getAudioInputStream(doc2.getInputStream());
    byte[] bufferTemp = new byte[(int)ais1.getFrameLength()];
    int nbOctetsLus = aisTemp.read(bufferTemp, 0, bufferTemp.length);
    java.io.ByteArrayInputStream baisTemp = new java.io.ByteArrayInputStream(bufferTemp);
    ais2 = new javax.sound.sampled.AudioInputStream(baisTemp, formatAudio, bufferTemp.length/formatAudio.getFrameSize());
    audioInputStreamList.add(ais1);
    audioInputStreamList.add(ais2);
    MixingAudioInputStream mixer = new MixingAudioInputStream(formatAudio, audioInputStreamList);
    javax.sound.sampled.AudioSystem.write(mixer, formatFichierAudio.getType(), fichierTemp);
    return fichierTemp;
    The only downside to this is that the music can be a little loud comparing to the speech. So I am now trying to use the AmplitudeAudioInputStream library to adjust the volume of the second file (it can be found here).
    Here are the additional lines I wrote to do this:
    ais2 = new javax.sound.sampled.AudioInputStream(baisTemp, formatAudio, bufferTemp.length/formatAudio.getFrameSize());
    org.tritonus.dsp.ais.AmplitudeAudioInputStream amplifiedAudioInputStream = new org.tritonus.dsp.ais.AmplitudeAudioInputStream(ais2, formatAudio);
    amplifiedAudioInputStream.setAmplitudeLinear(0.2F);
    audioInputStreamList.add(ais1);
    audioInputStreamList.add(amplifiedAudioInputStream);
    MixingAudioInputStream mixer = new MixingAudioInputStream(formatAudio, audioInputStreamList);
    javax.sound.sampled.AudioSystem.write(mixer, formatFichierAudio.getType(), fichierTemp);
    return fichierTemp;
    The problem is I always get the following exception when executing the code:
    could not write audio file: file type not supported: WAVE; nested exception is: java.lang.IllegalArgumentException: could not write audio file: file type not supported: WAVE (line 30, col:2)
    The error is on the last line (the write method), but after many hours of tests and research I cannot understand why this is not working... so I have added some "debugging" information to the code:
    System.out.println("file1 audio file format: " + formatFichierAudio.toString());
    System.out.println("file1 file format: " + ais1.getFormat().toString());
    System.out.println("file2 file format: " + ais2.getFormat().toString());
    System.out.println("AIS with modified volume file format: " + amplifiedAudioInputStream.getFormat().toString());
    System.out.println("Mixed AIS (final) file format: " + mixer.getFormat().toString());
    AudioFileFormat.Type[] typesDeFichiers = AudioSystem.getAudioFileTypes(mixer);
    for (int i = 0; i < typesDeFichiers.length ; i++) {
    System.out.println("Mixed AIS (final) #" + i + " supported file format: " + typesDeFichiers[i].toString());
    System.out.println("Is WAVE format supported by Mixed AIS (final): " + AudioSystem.isFileTypeSupported(AudioFileFormat.Type.WAVE, mixer));
    System.out.println("Destination file format: " + (AudioSystem.getAudioFileFormat((java.io.File)f)).toString());
    AudioInputStream aisFinal = AudioSystem.getAudioInputStream(f);
    System.out.println("Is WAVE format supported by destination file: " + AudioSystem.isFileTypeSupported(AudioFileFormat.Type.WAVE, aisFinal));
    try {
    // Ecriture du flux résultant dans un fichier
    javax.sound.sampled.AudioSystem.write(mixer, formatFichierAudio.getType(), fichierTemp);
    return fichierTemp;
    catch (Exception e) {
    System.err.println("Caught Exception: " + e.getMessage());
    Which gives the following result during execution:
    file1 audio file format: WAVE (.wav) file, byte length: 146964, data format: ULAW 8000.0 Hz, 8 bit, mono, 1 bytes/frame, , frame length: 146906
    file1 file format: ULAW 8000.0 Hz, 8 bit, mono, 1 bytes/frame,
    file2 file format: ULAW 8000.0 Hz, 8 bit, mono, 1 bytes/frame,
    AIS with modified volume file format: ULAW 8000.0 Hz, 8 bit, mono, 1 bytes/frame,
    Mixed AIS (final) file format: ULAW 8000.0 Hz, 8 bit, mono, 1 bytes/frame,
    Mixed AIS (final) #1 supported file format: WAVE
    Mixed AIS (final) #2 supported file format: AU
    Mixed AIS (final) #3 supported file format: AIFF
    Is WAVE format supported by Mixed AIS (final): true
    Destination file format: WAVE (.wav) file, byte length: 146952, data format: ULAW 8000.0 Hz, 8 bit, mono, 1 bytes/frame, , frame length: 146906
    Is WAVE format supported by destination file: true
    So everything tends to show that the format should be supported and the mixed AIS should be written to the file... but I still get the error.
    I am really confused here, if someone could help it would be great.
    Thanks in advance!
    PS: I have attached print screens of the actual script, without the "volume adjustment" code.

    Hi,
    well I started writing a similar solution but it did not work either so I just put it on hold.
    I also tried to get hold of the streaming "device" abstraction of UCCX to adjust the volume while "playing" but that was a dead end, too, unfortunately.
    Sorry about my previous comment on your StackOverflow post, that time I thought it was kind of out of context but I believe you only wanted to ask about this issue on all available forums.
    G.

  • How to get the file size (in bytes) for all files in a directory?

    How to get the file size (in bytes) for all files in a directory?
    The following code does not work. isFile() does NOT recognize files as files but only as directories. Why?
    Furthermore the size is not retrieved correctly.
    How do I have to code it otherwise? Is there a way of not converting f-to-string-to-File again but iterate over all file objects instead?
    Thank you
    Peter
    java.io.File f = new java.io.File("D:/todo/");
    files = f.list();
    for (int i = 0; i < files.length; i++) {
    System.out.println("fn=" + files);
    if (new File(files[i]).isFile())
         System.out.println("file[" + i + "]=" + files[i] + " size=" + (new File(files[i])).length() ); }

    pstein wrote:
    ...The following code does not work. Work?! It does not even compile! Please consider posting code in the form of an SSCCE in future.
    Here is an SSCCE.
    import java.io.File;
    class ListFiles {
        public static void main(String[] args) {
            java.io.File f = new java.io.File("/media/disk");
            // provides only the file names, not the path/name!
            //String[] files = f.list();
            File[] files = f.listFiles();
            for (int i = 0; i < files.length; i++) {
                System.out.println("fn=" + files);
    if (files[i].isFile()) {
    System.out.println(
    "file[" +
    i +
    "]=" +
    files[i] +
    " size=" +
    (files[i]).length() );
    }Edit 1:
    Also, in future, when posting code, code snippets, HTML/XML or input/output, please use the code tags to retain the indentation and formatting.   To do that, select the code and click the CODE button seen on the Plain Text tab of the message posting form.  It took me longer to clean up that code and turn it into an SSCCE, than it took to +solve the problem.+
    Edited by: AndrewThompson64 on Jul 21, 2009 8:47 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • What is the efficient way of insert some bytes into a file?

    Hello, everyone:
    If I want to insert some bytes into a file (for example, insert the bytes before all the original content of the file, or append the bytes to a file), and the size of the original file is very big. I am wondering what is the efficient way? Where can I get some sample codes?
    regards,
    George

    Thanks, DrClap.
    I have tried your method and you are correct. I have written a simple program which can be used to insert "Hello World " to the start of a file ("c:\\temp\\input.txt"), and I have verified that it can work. Please help to see whether it is correct and whether it has a more efficient way.
    public class TestDriver {
         public static void main(String[] args) {
              byte[] back_buffer = new byte [1024];
              byte[] write_buffer = new byte [1024];
              System.arraycopy("Hello World".getBytes(), 0, write_buffer, 0, "Hello World".getBytes().length);
              int write_buffer_length = "Hello World ".getBytes().length;
              int count = 0;
              FileInputStream fis = null;
              FileOutputStream fos = null;          
              try {
                   fis = new FileInputStream (new File("c:\\temp\\input.txt"));
                   fos = new FileOutputStream (new File("c:\\temp\\output.txt"));
                   while ((count = fis.read (back_buffer)) >= 0)
                        fos.write(write_buffer, 0, write_buffer_length);
                        System.arraycopy (back_buffer, 0, write_buffer, 0, count);
                        write_buffer_length = count;
                   //write the last block
                   fos.write(write_buffer, 0, write_buffer_length);
                   fis.close();
                   fos.close();
                   //copy content back into original file
                   fis = new FileInputStream (new File("c:\\temp\\output.txt"));
                   fos = new FileOutputStream (new File("c:\\temp\\input.txt"));
                   while ((count = fis.read (back_buffer)) >= 0)
                        fos.write(back_buffer, 0, count);
                   fis.close();
                   fos.close();
                   //remove temporary file
                   File f = new File ("c:\\temp\\output.txt");
                   f.delete();
              } catch (FileNotFoundException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
                   try {
                        fis.close();
                   } catch (IOException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                   try {
                        fos.close();
                   } catch (IOException e2) {
                        // TODO Auto-generated catch block
                        e2.printStackTrace();
              } catch (IOException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
                   try {
                        fis.close();
                   } catch (IOException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                   try {
                        fos.close();
                   } catch (IOException e2) {
                        // TODO Auto-generated catch block
                        e2.printStackTrace();
    }regards,
    George

  • Change MessageType name in xml file

    Hi experts,
    I have developed a receiver interface that creates an xml file and put it on an external server.
    Now other side says that this tag:
    <ns0:MT_MexElectronicInvoice_EDICOM xmlns:ns0="urn:Myfirm-EDICOM:MexElectronicInvoice">
    is not correct, they want another description:
    <ns0:MT_MexElectronicInvoice_myFirm xmlns:ns0="urn:Myfirm-EDICOM:MexElectronicInvoice">
    My question is: is possible to change MessageType tag in xml file without changing the message type structure name in Integration Repository?
    thanks
    fabio

    use another mapping which has the target  MT as  <ns0:MT_MexElectronicInvoice_myFirm xmlns:ns0="urn:Myfirm-EDICOM:MexElectronicInvoice">
    Add this mapping after the original mapping in your interface/operation mapping.
    This will be the easiest way to handle this requirement as you will only need to do a one to one mapping.
    Another option will be to write a java mapping to do a simple replace function for the string <ns0:MT_MexElectronicInvoice_EDICOM xmlns:ns0="urn:Myfirm-EDICOM:MexElectronicInvoice"> to  <ns0:MT_MexElectronicInvoice_myFirm xmlns:ns0="urn:Myfirm-EDICOM:MexElectronicInvoice">

  • InDesign CC 2014.2 has stopped asking me if I want to save changes when I close a file. It's automatically saving, but I don't always want to save changes.

    InDesign CC 2014.2 has stopped asking me if I want to save changes when I close a file. It's automatically saving, but I don't always want to save changes. Can anyone help?

    See: Replace Your Preferences

Maybe you are looking for

  • Negative sign display for CURR field in ALV grid report

    I have a field BETRG defined as CURR field of length 15, decimal places 2. The value may be negative or positive. In case of negative values I am using EDIT_MSK option in the field catalog to bring the negative sign to the left of the value as shown

  • How create ear to setup file or exe

    how i will create setup or exe from ear.

  • IPad Air mini won't charge

    I have been travelling for a month charging my iPad mini, ipad, and iPhone 5 with the same charger and cord. Now my iPad mini is dead and won't charge. Help!

  • What port do I connect my express to on the back of my modem?

    I am trying to install my new Airport Express but I do not know what port to use on the back of my modem. Do I go WAN to WAN or do I have to pick one of the other ports?

  • BDC_INSERT Problem

    hi, I am trying to create BDC program using transaction fv50. when i am execute the program,it is giving error like "BDC_INSERT,SCREEN.& IS INVALID". Will you plz tell me what's the reason . Thanks in Advance... Anjali Samadhiya.