Results 1 to 2 of 2
  1. #1
    TampaTechGuy is offline Member
    Join Date
    Jan 2008
    Posts
    8
    Rep Power
    0

    Default ByteArray to XML Doc

    Hi -

    I am trying to write a byte array to an xml document. First time doing it. Here is my code. I am getting some crazy stuff back in the tag, but I am not sure it is correct. Can someone plz help!

    writer.write("<Image>");

    InputStream is = new FileInputStream(pdf);
    byte[] buffer = new byte[8192];

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    int bytesRead;

    while ((bytesRead = is.read(buffer)) != -1) {
    baos.write(buffer, 0, bytesRead);
    }

    byte[] bytes = baos.toByteArray();
    for (int i = 0; i < bytes.length; i++){
    writer.write(bytes[i]+"");
    }

    writer.write("</Image>");

    Here is my output:

    <Image>37806870454946521037-30-29-49-45105132483211198106106060477610111010311610432495 45451104770105108116101114324770108971161016810199 111100101106262101151161141019710910120-100-1158891111-38-5422126-258744-23-12-95-107-64-52-5951-74-111-5031-110-109-8344097-85-89829528-37105-6855-74-39-74105-62-65-3310710810418-49114902017123-26-5102-35103-42-64-128-61-120332140-4-114-78-6363-125-117-19-64-591-49-125109609656-83-44-239-121-377-23-9730-68-4572-1311112441-12811-40621262-62-89-199513-945112-7929124709-5281-36-4540-48-47-127-4992-4-1775466140-6515921110-6465-72-98-6193-64-65502560-687116-12750-56-122-92-72-29-119-33334137289583-110-1161222-21047698-80-71-62-105-89-10523-93-991123327-8-1165379-69-63-35-5344-1766-69-53-997-5108-24-61-9-87-110-1-39-124-1115511128535101-126-10497-120-112-62-10216101-57-37-8046-45-25103-72-5012720105-108-12884-8286-34-2454789287-101098-7258-85-72-689355310887895943746-11810392-107965-109100-105-7613-7712556-124-5327-112821157-22-8910-11790-201181128938-554-66125-12-75-2-1092-9171943237-672-17-82-1688-41-5-55120-4-12-12-28100-57-84117-1271921256515-76-2919-98-6976-53-86-9821-39-66-105-46-1738-55125-65-10510257106-107-123-113-24-88-27252-925101-95-5526121-42-17-60-102-19-6252-61-88622037-38-1052257-63-109-32-6-843510925102-11913-27-68-55482762-9979-815567-40-84-26-53-598790-124-1059-100-3736-697974-72-114-5-27882887114-50-1031040-1381-122-4629-4124117-47-65-70-123-2612444-39-1047-54-91-1057115-6537-76-349330-11633-311444-38-271161948-582011-108-943773972550-192396-95-1033011561-585012108-110890-110-10742-21-16104-62-1594-868-527750-287101113327464122-36-47-102-64-6583541032586-2027-3-610188-8-33-11297101-6434-37-17-118119-5988-108-23-201108-41-53-103-4547-5874-128105-4-41-95-86-33199981-66-9211761-1241218238127-3744-91-36-1016-24-58-12-68-99-652785-91100-61-74-9411698-3712451242-2-11751-2944-58148418-615412438119-12670-110-5980-6372122-12610569-2031034986-9686-121-70-86-616078-13-17611144410-125566086-350-8440-99-36115-2162-7389-100-1933-8780-5216868193-10429-111-5333-68-86-35127-2070-601160-40-128-556455-3-121104-9876-1-4761-2293110873030-102-76122-1009711214103-13-4312-83101-109-3654581216425433-11214-87-46-59-8-118-8829-8229-11319-24-7-1211-12711841-67471118-92-57281716-32-49-11-111-8696-41-1552-91-592981-69-36119-10434-64-2150-87-945037159-105714-87-41146235-4862-9441-81-363811326-11-44-73102-663541-46101-461006523-5726-36-57-69-2449-119155942-113-5111867-711286-2067-62-117-38-7652-10899-18-623188-11568-12712146-26-1183624-45-8456-2853-5215-12490-10492-46-1786871271711710769122939728-1011-47115-116-98-118-59389331247750-38-126-7925-84-7386108108127-91-4-42-70-907810832-47-18-100-54-124-6450-12190-73-83192778108-48-8950-79-79-13-115355-45-51-2643-36-6878-535194-73105-71-68-6-13-21989-73-50-1005611379-4368-8-126-717651-595-29-6785101-7786-1-15891-5187-53-591205891108-89-73-41-81-1158-77-50122-83-42-167-67-447210-94-87-45-126-103-38-7869124-6430-114-222-75-10-16-114741748068460-18-4654124-64-5-9571-3211764103-407927283-9184-69-353-14101103-1252760-9-1410-1798-26-13106124-71-66-980-961-82124-2741-4795-113-2680-457655110114-51-5990-101-85109-48-68-104-77-83-10312725-621217658-3686-34-52-65121013-49-271021912161-1106-24116112-38-109-62-979-109-26-555885212262-61205955-3563123-83-69-6112593-44-31-822-20-753210959-12773127428893-5-8182-6338-68-971054-2-3843220-948315194114-6599-21245-53-432254-117-11-26122-74112487118738837-24-120104119-12019-8121-353-20-63126-2-50-112551193940114-64-4538-6-10140105-68-19581106-57-6122-83-77-33987-9745-77-72-67-10673-2732884-421730-9049-4469-455781-12676-37-828-34-88397090122-114-48-72-51-22-1845-84-112694118-6-19-7989111-203310675-7613-9380-25-122-47608113-93-80-3883-20-503811281-102-969790953712182-9017-58-81-2355112463-13-69958-26889740-10-5-35-4712975553-127-49-12148-81-45-7025-64-741365105-7555-1016812-4510-66-108120-9173-883136801373-761254766-859-80-47-78-56-10933-16-47-6-1588-918126-26-4053-113-42-40337-4032-108-55-61-63-56-7-34-2259457-38-8431-9574118738487112111-2025-1265958-37-109235310242841171717-943-9317-7312691120-9317124-5242110410912672-30111-973812014-7662-117127-102288647-38-24-47-227182-106105-1162212039100-12295-1049349-363197236213-63127-9393-83576119-31-31425-631048563-110-5136-22-55-7085-36-10-29-2450-72126481264923-128-13428-105-5697-33110-44123-4557669065-986057111-12728-35-118-18671031333-87-93-10686633422-1-16-27-116-52123126565-99-72-33-67-64-99-38-72-8-48-48-37-104-124-7-79-39266692444270123-1098081-7951-109-24-108-121-78-5626113-583-124-61-7012512512-159827-99-69-5012711-5439-50101011101001151161141019710910101110100111981061 05332483211198106106060478097114101110116325232483 28210476711111011610111011611532513248328210478412 11121013247809710310110478210111511111711499101115 32606047801141119983101116329147806870324784101120 11632477310997103101663247731099710310167324773109 97103101739310477011111011632606047704932493248328 21047705032503248328210626210626210477710110010597 66111120329148324832535753325652509310478211111697 11610132574810626210101110100111981061049324832111 98106106060476697115101701111101163247721011081181 01116105999745661111081001047841211121013247701111 10116104769110991111001051101033247871051106511011 51056911099111100105110103104783117981161211121013 24784121112101491062621010111010011198106105032483 21119810610606047669711510170111110116324772101108 11810111610599971047841211121013247701111101161047 69110991111001051101033247871051106511011510569110 99111100105110103104783117981161211121013247841211 12101491062621010111010011198106105232483211198106 10606047841211121013247809710310111510476711111711 01163249104775105100115329153324832829310626210101 11010011198 ETC ETC</image>

  2. #2
    TampaTechGuy is offline Member
    Join Date
    Jan 2008
    Posts
    8
    Rep Power
    0

    Default

    Ahhh just saw that I was suppossed to post with code tags! Sorry- fairly new here.

Similar Threads

  1. bytearray to string conversion
    By mew in forum New To Java
    Replies: 1
    Last Post: 01-28-2008, 10:39 AM
  2. Reading a File into ByteArray
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-15-2008, 03:19 PM
  3. Replies: 0
    Last Post: 11-27-2007, 10:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •