Encode data

I want to encode the US-ASCII data into UTF-8.
For that what is the procedure.
I have to use
1.InputStreamReader and OutPutStreamReader
2.Charset/CharsetEncoder/CharsetDecoder
What is the difference between the two processes?
Process 1:
FileInputStream fis = new FileInputStream(inputFile);
InputStreamReader isr = new InputStreamReader(fis,"UTF-8");
FileOutputStream fos = new FileOutputStream(outputFile);
OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8");
Process 2:
Charset charset = Charset.forName(encode);
CharsetDecoder decoder = charset.newDecoder();
CharsetEncoder encoder = charset.newEncoder();

InputStreamReader is for converting non unicode
charecter bytes to unicode.
outpuStreamWriter is for converting unicode charecter
to non unicode byte stream.is it correct?Yep, that's correct...Are you sure? Maybe it's just badly worded, but it doesn't sound correct to me. A CharsetDecoder converts a ByteBuffer to a CharBuffer, while an InputStreamReader converts a stream of bytes to a stream of characters. You couldn't replace one with the other--in fact, an InputStreamReader may use a CharsetDecoder under the hood, depending on how you construct it.
I think it's a mistake to talk about converting "to (or from) Unicode", especially in this case. Sure, Java uses one of the Unicode-standard encodings internally, but which one it uses is an implementation detail that you don't need to know. All you need to know is which encoding was used to create the byte stream you're trying to read at the moment.
@ssa_sbobba, if I understand you correctly, you want to read a file that you believe to be in the US-ASCII encoding, and write the text back out using the UTF-8 encoding. That's simple enough:   FileInputStream fis = new FileInputStream(inputFile);
  InputStreamReader isr = new InputStreamReader(fis,"US-ASCII");
  FileOutputStream fos = new FileOutputStream(outputFile);
  OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8"); If that's all you're doing, though, it's pointless; as Jos pointed out, US-ASCII is a subset of UTF-8, so the new file will be identical to the old one.

Similar Messages

  • Binary to Voltage Conversion of encoder data on cRio 9073 using FPGA

    I am using FPGA with a cRio 9073 to acquire torque and absolute quadrature encoder values. It says in the FPGA instructions that the documentation for the 9073 should include the binary to voltage conversion, but when I looked at the documentation, it wasn't there. Where can I find the conversion value or function to convert binary encoder data back to voltage? The encoder is hooked up to an analog converter and is acquired with a 9215 AI (+-10V differential). Thanks

    There are individual formulas for one or a group of modules.
    LabView examples path:
    LabVIEW 2010\examples\CompactRIO\Basic IO\Analog Raw Host Calibration\AI Raw Host Calibration
    LabView help topic 
    Converting and Calibrating CompactRIO Analog Input Values (FPGA
    Interface)
    Best regards
    Christian

  • Illegal character in Base64 encoded data

    Hi,
    I'm trying to get a print out the public key as a String, which I am getting it in as a base64 encoded, but I get error:
    Exception in thread "main" java.lang.IllegalArgumentException: Illegal character in Base64 encoded data.
    Code below:
    public static void main(String[] args) {
              File pubKeyFile = new File("C:\\usercert.pem");
              StringBuffer buffer = new StringBuffer();
                   try {
                        FileInputStream fis = new FileInputStream(pubKeyFile);
                        try {
                             InputStreamReader isr = new InputStreamReader(fis, "UTF8");
                             Reader in = new BufferedReader(isr);
                             int ch;
                             while((ch = in.read()) > -1) {
                                  buffer.append((char)ch);
                             in.close();
                             String key = buffer.toString();
                             System.out.println("key is: " + key);
                                          //This is where the code fails:
                             String keyDecode = Base64.decodeString(key);
                             System.out.println("key ecode is: " + keyDecode);
                        } catch (UnsupportedEncodingException e) {
                             // TODO Auto-generated catch block
                             e.printStackTrace();
                        } catch (IOException e) {
                             // TODO Auto-generated catch block
                             e.printStackTrace();
                        }

    Hi ejp,
    It's a rsa public, the usercert.pem looks like below,
    so since it's not an x509 certificate not sure if I
    can read it using a
    java.security.cert.CertificateFactory?
    Basically I just want to print the public and private
    key out as a String. Any help is appreciated.
    -----BEGIN PUBLIC KEY-----
    MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCg8yo6rDhsNiwUfV
    R37HgF4bWq
    oG13Nd9XLT+Z0VLzCkWJZOdzGNQnnm7ujoQ8gbxeDvIo9RG5I3eZte
    BwD91Nf6P/
    E9lvJQDL2Qnz4EXH/CVW9DeEfvY1UJN9kc6q6KkYEPWssvVvlDOp2s
    lbEKZCJtaP
    vVuGCAqfaps8J0FjOQIDAQAB
    -----END PUBLIC KEY-----
    import java.security.KeyFactory;
    import java.security.interfaces.RSAPublicKey;
    import java.security.spec.X509EncodedKeySpec;
    import sun.misc.BASE64Decoder;
    public class MakeRSAPublicKeyFromPEM
        public static void main(String[] args) throws Exception
            final String publickeyAsString =
                    "-----BEGIN PUBLIC KEY-----\n"+
                    "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCg8yo6rDhsNiwUfVR37HgF4bWq\n"+
                    "oG13Nd9XLT+Z0VLzCkWJZOdzGNQnnm7ujoQ8gbxeDvIo9RG5I3eZteBwD91Nf6P/\n"+
                    "E9lvJQDL2Qnz4EXH/CVW9DeEfvY1UJN9kc6q6KkYEPWssvVvlDOp2slbEKZCJtaP\n"+
                    "vVuGCAqfaps8J0FjOQIDAQAB\n"+
                    "-----END PUBLIC KEY-----\n";
            final BASE64Decoder decoder = new BASE64Decoder();
            final byte[] publicKeyAsBytes = decoder.decodeBuffer(publickeyAsString.replaceAll("-+.*?-+",""));
            final X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(publicKeyAsBytes);
            final KeyFactory keyFactory = KeyFactory.getInstance("RSA");
            final RSAPublicKey publicKey = (RSAPublicKey)keyFactory.generatePublic(publicKeySpec);
            System.out.println("Modulus ........... " + publicKey.getModulus());
            System.out.println("Public exponent ... " + publicKey.getPublicExponent());
    }

  • Encoded data to  files

    Hi Expts,
    My requirement is i have to encoded data to  files using file receiver adapter.
    am also using FCC.
    can anybody help me on this how to approach.
    Thanks&Regards,
    Mp Reddy

    Hi,
    >>>>My requirement is i have to encoded data to files using file receiver adapter.
    in file receiver adapter specify encoding in:
    - select  File Type
    - then Text
    - next under File Encoding, specify a code page.
    examples of code pages from:
    http://help.sap.com/saphelp_nw04/helpdata/en/bc/bb79d6061007419a081e58cbeaaf28/content.htm
    this way your file will be encoded
    Regards,
    Michal Krawczyk

  • Get the Encoder Data from NI Robotics Starter Kit 1.0

    I want to make a perfect 90 degree turn using the encoder Data from Robotics Starter Kit 1.0. Now I am doing it giving the angular velocity and controlling the time. But, the problem is, it's not perfect all the time. It is not repeatable. So, I want to use the encoder Data to turn it 90 degrees perfectly. So, How could I get the Quadrate Encoder Data from the motors (What VI should be used?). 

    Hey Mashfique,
    Sorry for the delayed response. I believe that with the Robotics Starter Kit 1.0 you aren't actually suppose to worry about which of the FPGA I/O correspond to which sensor because the Robotics VIs abstract that for you by design. Here's a link that you might find interesting that describes how to communicate with the FPGA to steer a robot using either the Servo's angular position or velocity:
    http://zone.ni.com/reference/en-XX/help/372983D-01​/lvrobogsm/robo_skit_programming/#skit_steering
    In the above link for example, they mention using the Write Sensor Servo Angle VI to set the angle that you want to rotate the Servo to.
    Regards,
    Ryan

  • Encoder data and speed calculatio​n with PXI 4472B card

    Hi,
    I want to collected time, vibration, encoder and speed signal in one file. I am trying to develop NI by using PXI 4472B and LabView 8.6. Everything is okay but getting only one rpm for speed data. I want to collect continuous data for 15 sec (constant speed) and 15 sec (ramp up speed).
    q1. Would you please look into the VI and provide me some suggestions to get continuous speed and all data?
    q2. What is the best way (programming etc.) to collect constant speed (100 rpm) and ramp up speed (50-1000rpm) data in two files automatically from one test? Any help?!
    New Labview user.
    Regards, Niaz
    Attachments:
    Encoder data Collector.vi ‏156 KB

    Hi Chris,
    Thank you for your warm response. Here is the status:
    1. I already tried to use 'Analog Tacho processing' sub-pallette. See the attachment, but the RPM value is not the same/similar with the actual known RPM. However, 'Timing trans..' sub-pallette shows similar speed in terms of frequency to actual known RPM. Do frequency and speed profile value in NI should not be the same/very close? Encoder disk is of 60 pulse/rev and using laser TTL to get the pulses, signal input is into 4472B. Does it neet to extra processing to count the edges of rising?
    2. I prefer ASCII or TEXT. Experiment is for one ramp-up (50-1000rpm) and one steady (100 rpm) for 15 sec each. I will use this data in Matlab. I am looking for help in programming so that single experiment will divide into two separate files of ramp-up and steady speed. File will consists of time, vibration, encoder value (0,1...) and speed.
    Kind regards, Niaz
    Attachments:
    Data Collector-4NI.vi ‏190 KB

  • Please prefix 'mp4:' to the stream name to record H264/AAC/HE-AAC encoded data at FMS using DVR...

    I was able to modify the main.asc file in the application/livepkgr directory to include:
    * DVRSetStreamInfo :
    * This prototype was created to allow DVR recording funtionality to FLME to FMS
    Client.prototype.DVRSetStreamInfo = function (info)
        var s = Stream.get( "mp4:" + info.streamname + ".f4v" ) ;
        if (s)
            if (info.append)
            s.record ("append") ;
            else
            s.record () ;
            s.play (info.streamname) ;
    I get three status messages in the FLME encoding log:
    Requested DVR command has been successfully issued to Primary FMS server for stream livestream1
    Requested DVR command has been successfully issued to Primary FMS server for stream livestream2
    Please prefix 'mp4:' to the stream name to record H264/AAC/HE-AAC encoded data at FMS using DVR feature
    Now I have a few issues:
    1. How to I fix the issue with the 3rd status message "Please prefix 'mp4:' to the stream name to record H264/AAC/HE-AAC encoded data at FMS using DVR feature" since the code above is prefixing the "mp4:" to the stream name.
    2. In the applications/livepkgr/streams directory there is a file called "undefined.f4v" which is telling me the code above isn't passing the info.streamname variable.
    3. Also, what do I need to do to playback this .f4v file. I've tried opening it with Adobe Media Player, but it doesn't recognize it.
    I'm obviously using multi-bitrate streaming and that is working flawlessly.  My goal is to record this livestream to later playback as an mp4 file.
    Any ideas?
    UPDATE:
    I know on page 15 of the FMS 4.5.1 developers guide, "Configure DVR (HDS)" under "Publish a DVR stream", it states "To Publish a DVR stream from FLME, DO NOT check Record OR check DVR Auto Record. Publish the stream just as you publish any live stream. In the next section "Play DVR streams" is states that I can use SMP (Stobe Media Playback), which I am.  So that brings up two more questions:
    1. Why is my SMP Player not displaying the DVR funtionality (See image):
    In my SMP configuration, my streamType is "LiveOrRecorded" - default. There is a streamType = "dvr", but will I lose live funtionality?
    2. If I want to later on, package the stream into an mp4 file and play it back later for those who missed the live stream, what is the best approach for that?
    Message was edited by: giostefani

    Two things: You need to have "DVRCast" application on server-side i.e. "dvrcast_origin" for DVR recording to work and secondly for mp4 recording your stream name should be "mp4:<streamname>.mp4" while publishing.

  • How to parse 10 byte encoded data from Omegatte HH306 Thermometer/Datalogger?

    I am trying to write a simple code for an OMEGAETTE HH306 Thermometer/Datalogger from omega.com.
    Here is the problem. I communicate with the device via RS-232, using Labview 8.5.1 and windows xp. I query it for "all encoded data", which is basically the only option. It returns 10 bytes of encoded data, the manual describes the meaning of each byte, and I understand all of it. The problem is that I cannot seem to parse the information for use within labview, for example: I want to extract the temperature and simply display it.
    upon query, I get: 10bytes (read as a string from the serial port read buffer):     HEX display: 02 00 A8 B6 48 FF EF B6 49 03      This is perfect, and what I expect.     Codes Display: \02\00\A8\B6H\FF\EF\B6I\03               The Normal Display is a series of special characters, which I don't understand, especially since I don't think they represent the ascii characters that should correspond to the hex numbers returned!   For the life of me, I cannot figure out how to extract the information (which is the 6 48 in the hex display) from what is returned. All the string manipulation functions seem to only work on what is given in the Normal Display. (The 4th and 5th byte of the data are the BCD codes for the temperature: for example the temperature was 64.8 degrees farenheight when I took this reading).
    Can anyone help me to parse the data returned by this device?
    Solved!
    Go to Solution.

    Ok... I think I figured it out. I found this: http://digital.ni.com/public.nsf/websearch/77C8F61D36F5A23086256634005ACB38?OpenDocument.
    I guess the garbled normal display is the ascii characters corresponding to each hex number. I am just not used to seeing ascii characters beyond the decimal number 127, or hex 7F.
    So basically, to parse the 10 bytes of data:
    1) break up the string read from the serial port into the 10 individual ascii characters (using  String subset vi)
    2) wire each output string into the left input of 10 distinct Type Cast vi's.
    3) wire a U8 constant into each "type" terminal of the Type Cast vi's.
    4) wire the string output of each Type Cast vi into the input of a  number to hexadecimal string vi.
    5) concatenate or use as you would like the hex numbers (now in string format) that result.
    Cheers.

  • XSL and url encoded data issue

    I have a large XML document, which has the data in it URLEncoded to escape the nasty chars.
    When I run it through the xalan XSL parser and feed the output to the browser in my servlet, the resultant html has the URLEncoded chars in it. For instance the '/' is still showing up at %2F etc... However, if I can't URLDecode the whole xml document. Is there a simple way for decode the URL chars, without doing too much trickery?
    Thanks!
    Modoc

    You can URL-encode XML data if you like, whatever you mean by "nasty chars" I don't know. The result is perfectly legitimate XML and XSLT will translate it perfectly well. But it won't decode it, that is none of its business. I suppose it would be possible to write an XSLT function to do URL-decoding, but my preference would be to do that some other way. Or not to URL-encode in the first place.

  • Writing UTF8 encoded data on file system.

    Hi,
    Could some one tell me what is wrong with the following code.
    try
    fos = new FileOutputStream(new File ("A.txt")) ;
    catch(FileNotFoundException fnfe)
    throw new Exception ("FileUtility constructor 2 - FileNotFoundException ", fnfe);
    try
    // Create OutputStreamWriter to a fileOutputStream with encoding
    OutputStreamWriter osw = new OutputStreamWriter(fos, encoding_);
    // Create buffered writer over the OutputStreamWriter
    _buffWriter            = new BufferedWriter(osw);
    buffWriter.write(data,0,data_.length());
    _buffWriter.newLine();
    catch(IOException _ioException)
    GemmsUtility.showMsg("FileUtility writeData - IOException ["+ioException.toString()+"]",bDebug);
    _ioException.printStackTrace();
    catch(UnsupportedEncodingException usee)
    throw new Exception ("FileUtility constructor 2 - UnsupportedEncodingException ", usee);
    I find some junk characters in "A.txt". When I open "A.txt" i found some junk characters. Your help will be appreciated.
    Thanks
    -Sri

    You are retrieving characters from a character set.
    You are writing characters via a character set.
    And then you are viewing them via yet another character set.
    If one character set does not have a character that the other set does then you have a problem.
    Now it is possible that some of the above character sets are the same. Or they could all be different.
    I can however guarantee that with kanji that you are going to spend some time figuring it out.
    The first step is to verify what chars are in the database and what ones are in the text file.
    The way that you do that is to print the character values, in java, as hexadecimal values. Then you open the text file in a hexadecimal editor and see what is there. Then you create a text file with what should be there and compare the differences. It would also help if you could do the same thing in the database (using a database tool, not java.)

  • Error in encoded data in 2D barcode

    Hi, I have been met with a strange problem.
    I have a form with a 2D barcode. The barcode is a pdf417 barcode and the character encoding is ISO-8859-1.
    Often the field data include special characters as Æ – Ø – Å – Ü
    Most of the time everyting is fine. But now and then (I guess one in a thousand) it seams that the encodeding of the special characters get wrong. e.i in the form field the data is ”Ørskov” but the barcode data says ”Ãrskov”. I have not been able to reproduce the error in house but I have seen a few on incomming forms in the last 6 month.
    Where should I start troubleshooting? Has it anything to do with the client’s version or settings of Adobe Reader?
    Is there anything I can do to prevent this error?
    Regards,
    Kirstine

    I have now been able to reproduce the error.  The data get encoded wrong when the form is filled out in Adobe Reader 8. (Or at least in Reader 8.2 which is the version I have for testing).
    The easy way out for me would be to ask all the clients to upgrade Adobe Reader but that is not practically posible, as we have thousand of clients using this form.
    Would it be posible to script my way out of this?
    Kirstine

  • Encoding Data

    I have been looking over lzw compression for a couple hours now and i understand how it works as far as all the table holding and such. what i don't understand is how the data is being read in as 12bit and being saved as 8bit and then being reread as 12bit. can i get somebody to explain this please? i would just like the 12-8 bit part, then i will try the 8-12 and see if i can do it.

    Hi Venkat,
    I have now managed come up with a viable solution the code128 barcodes with reports 6i. It involves getting the IDAutomation universal barcode fonts with a developer licence. With that you get the source code for the associated PL/SQL libraries. If you take the source and creat database packages from it, then you can call the function in the same way from the report, but without the reports 6i limitations on the code. As the universal barcodes are encoded with all uppercase charcter strings, there is no issue with character sets.
    Hopefully this may be of use to you.
    Mike

  • Encoder data into a PD closed control loop

    Hey, basically for our current project, we have to create a program that will run through a cRio for a buggy, the buggy has 2 motors of maximum 12V supply. The bugggy must travel a certain distance, 8m, over an uneven distance and end up at a particular end point.
    we are currently trying to create a a closed loop control system with a ramp input, then a Proportional Derivative system to alter the error from the encoders, which record the actual speed of the wheels.
    However we are unsure about how to go about creating this in labview or simulate this as we do not have access to the actual practical equipment at the moment, any help or links to guides about how to go about this or general help would be greatly appreciate, feel free to ask any questions if i have I can be clear about anything anymore, but we are really struggling atm.

    Thanks for replying,
     Basically we arent using a control and simulation loop anymore as it was proving to be too advanced for what we need to do. We arent using any toolkit in particular, however our vi is within a case structure, the attached folder is the vi that we have created so far.
    The simulated signals are to represent the encoder velocity values that we will obtain. If you can help us with any of the following it would be of great help:
    1. We currently a ramp input to simulate the acceleration at the start but are unsure on how to keep a constant velocity after the maximum velocity is reached and to have a deceleration at the end.
    2. We are unsure if what we have as P controller will actually minimise the error between desired velocity and actual velocity
    3. We dont have a stop condition, it has to travel a known distance, can this be worked out from the data gathered from the encoders and a stop condition created?
    We have access to the majority of applicable toolkits, shown in the attached photo.
    Any guidance would be greatly appreciated.
    Attachments:
    buggy control algorithm.vi ‏65 KB
    Tool pallette.png ‏39 KB

  • Incorrect UTF-8 encoded date in XML reports under German Win in March (IE error)

    TestStand XML reports are marked as UTF-8 encoded. But those reports generated under Win2k German in March (written as "März" in German) cannot be displayed in the Internet Explorer because the umlaut character of the month name is not correctly UTF-8 encoded.

    Hi
    I have attached the modified modelsupport2.dll and the ReportGen_Xml.seq which fixes the problem. I also attached the modified report.c and modelsupport2.fp files.
    If you have not made changes to modelsupport2.dll and reportgen_xml.seq you can add the modified files to \Components\User\Models\TestStandModels\ folder and the TestStand engine should use the version under the user folder.
    If you have made changes to ReportGen_Xml.seq and ModelSupport2.dll then you will need to move the changes in the below files to the files under the User folder.
    FYI: If you want to create a new component or customize a TestStand component, copy the component files from the NI subdirectory to the User subdirectory before customizin
    g. This ensures that installations of newer versions of TestStand do not overwrite your customization. If you copy the component files as the basis for creating a new component, be sure to rename the files so that your customization do not conflict with the default TestStand components.
    The TestStand Engine searches for sequences and code modules using the TestStand search directory path. The default search precedence places the \Components\User directory tree before the \Components\NI directory tree. This ensures that TestStand loads the sequences and code modules that you customize instead of loading the default TestStand versions of the files.
    I hope this helps.
    Regards
    Anand Jain
    National Instruments.
    Attachments:
    ModifiedFiles.zip ‏384 KB

  • Does File Input stream encode data

    Hi,
    When I retrieve a binary stream of an image from a database and print out all the bytes and then retrieve data with a FileInputStream from the same image stored as a file, and print the results, the 2 printouts are completely different. Can anyone explain why?
    Thanz

    However, the InputStreams do treat bytes as signed entities (-128 to +127 rather then 0 to 255). If you just print these out then you will get odd results which do not match the data you are expecting.
    If you do the following
    int tmp = b & 0xFF;
    where b is a byte from your input then tmp will contain the unsigned value of that byte rather then the signed value.
    matfud

Maybe you are looking for