Project

General

Profile

« Previous | Next » 

Revision 5760

use detected document encoding or Metacat's default encoding (UTF-8)

View differences:

test/edu/ucsb/nceas/metacat/dataone/CrudServiceTest.java
32 32

  
33 33
import edu.ucsb.nceas.MCTestCase;
34 34
import edu.ucsb.nceas.metacat.IdentifierManager;
35
import edu.ucsb.nceas.metacat.MetaCatServlet;
35 36
import edu.ucsb.nceas.metacat.client.MetacatAuthException;
36 37
import edu.ucsb.nceas.metacat.client.MetacatException;
37 38
import edu.ucsb.nceas.metacat.client.MetacatInaccessibleException;
......
883 884
        checksum.setAlgorithm(ca);
884 885
        sm.setChecksum(checksum);
885 886
        //set the size
886
        sm.setSize(testDoc.getBytes().length);
887
        sm.setSize(testDoc.getBytes(MetaCatServlet.DEFAULT_ENCODING).length);
887 888
        //submitter
888 889
        Principal p = new Principal();
889 890
        p.setValue("joe");
src/edu/ucsb/nceas/metacat/lsid/LSIDAuthorityMetaData.java
32 32
import java.io.InputStreamReader;
33 33
import java.io.Reader;
34 34
import java.io.StringReader;
35
import java.io.UnsupportedEncodingException;
35 36
import java.util.Hashtable;
36 37
import java.util.ResourceBundle;
37 38
import java.util.Enumeration;
......
52 53
import com.ibm.lsid.server.LSIDServerException;
53 54
import com.ibm.lsid.server.LSIDServiceConfig;
54 55

  
56
import edu.ucsb.nceas.metacat.MetaCatServlet;
55 57
import edu.ucsb.nceas.metacat.client.Metacat;
56 58
import edu.ucsb.nceas.metacat.client.MetacatFactory;
57 59
import edu.ucsb.nceas.metacat.client.MetacatInaccessibleException;
......
298 300
                        + "	<pred:title xmlns:pred=\"http://purl.org/dc/elements/1.1/\">There is no metadata for this LSID.</pred:title>\n"
299 301
                        + "</rdf:Description>\n" + "</rdf:RDF>\n";
300 302

  
301
        return new ByteArrayInputStream(result.getBytes());
303
        ByteArrayInputStream resultBytes = null;
304
        try {
305
        	resultBytes = new ByteArrayInputStream(result.getBytes(MetaCatServlet.DEFAULT_ENCODING));
306
		} catch (UnsupportedEncodingException e) {
307
			// TODO Auto-generated catch block
308
			e.printStackTrace();
309
		}
310
		return resultBytes;
302 311
    }
303 312

  
304 313
    /**
......
321 330
                        + "	<pred:title xmlns:pred=\"http://purl.org/dc/elements/1.1/\">There is more than one metadata document for this LSID - which confuses me right now.  Try again soon and I'll be less confused.</pred:title>\n"
322 331
                        + "</rdf:Description>\n" + "</rdf:RDF>\n";
323 332

  
324
        return new ByteArrayInputStream(result.getBytes());
333
        ByteArrayInputStream resultBytes = null;
334
        try {
335
        	resultBytes = new ByteArrayInputStream(result.getBytes(MetaCatServlet.DEFAULT_ENCODING));
336
		} catch (UnsupportedEncodingException e) {
337
			// TODO Auto-generated catch block
338
			e.printStackTrace();
339
		}
340
		return resultBytes;
325 341
    }
326 342

  
327 343
    /**
src/edu/ucsb/nceas/metacat/restservice/ResourceHandler.java
62 62
import edu.ucsb.nceas.metacat.DBUtil;
63 63
import edu.ucsb.nceas.metacat.IdentifierManager;
64 64
import edu.ucsb.nceas.metacat.McdbDocNotFoundException;
65
import edu.ucsb.nceas.metacat.MetaCatServlet;
65 66
import edu.ucsb.nceas.metacat.MetacatHandler;
66 67
import edu.ucsb.nceas.metacat.client.InsufficientKarmaException;
67 68
import edu.ucsb.nceas.metacat.dataone.CrudService;
......
1227 1228
    private InputStream stringToStream(String s)
1228 1229
    throws IOException
1229 1230
    {
1230
        ByteArrayInputStream bais = new ByteArrayInputStream(s.getBytes());
1231
        ByteArrayInputStream bais = new ByteArrayInputStream(s.getBytes(MetaCatServlet.DEFAULT_ENCODING));
1231 1232
        return bais;
1232 1233
    }
1233 1234
    
......
1411 1412
                    
1412 1413
                    writeString = s.substring(0, result[0]);
1413 1414
                    //System.out.println("writing1: " + writeString);
1414
                    fos.write(writeString.getBytes());
1415
                    fos.write(writeString.getBytes(MetaCatServlet.DEFAULT_ENCODING));
1415 1416
                    //we're done.  break and return;
1416 1417
                    return s.substring(result[0] + result[1], s.length());
1417 1418
                }
......
1436 1437
                if(searchForBoundary)
1437 1438
                {
1438 1439
                    //System.out.println("writing2: " + s);
1439
                    fos.write(s.getBytes());
1440
                    fos.write(s.getBytes(MetaCatServlet.DEFAULT_ENCODING));
1440 1441
                }
1441 1442
                numread = is.read(b, 0, 1024);
1442 1443
                if(numread != -1)
src/edu/ucsb/nceas/metacat/util/MetacatPopulator.java
41 41

  
42 42
import org.apache.commons.io.IOUtils;
43 43

  
44
import edu.ucsb.nceas.metacat.MetaCatServlet;
44 45
import edu.ucsb.nceas.metacat.MetacatHandler;
45 46
import edu.ucsb.nceas.metacat.MetacatResultSet;
46 47
import edu.ucsb.nceas.metacat.MetacatResultSet.Document;
......
194 195
                    checksum.setAlgorithm(ca);
195 196
                    checksum.setValue(checksum(dataDocIs));
196 197
                    dataDocSysMeta.setChecksum(checksum);
197
                    dataDocSysMeta.setSize(dataDocText.getBytes().length);
198
                    dataDocSysMeta.setSize(dataDocText.getBytes(MetaCatServlet.DEFAULT_ENCODING).length);
198 199
                    dataDocSysMeta.addDescribedBy(sysmeta.getIdentifier());
199 200
                    boolean error = false;
200 201
                    //create the data doc on d1
......
294 295
        sm.setObjectFormat(format);
295 296
        
296 297
        //create the checksum
297
        ByteArrayInputStream bais = new ByteArrayInputStream(doc.doctext.getBytes());
298
        ByteArrayInputStream bais = new ByteArrayInputStream(doc.doctext.getBytes(MetaCatServlet.DEFAULT_ENCODING));
298 299
        String checksumS = checksum(bais);
299 300
        ChecksumAlgorithm ca = ChecksumAlgorithm.convert("MD5");
300 301
        Checksum checksum = new Checksum();
......
303 304
        sm.setChecksum(checksum);
304 305
        
305 306
        //set the size
306
        sm.setSize(doc.doctext.getBytes().length);
307
        sm.setSize(doc.doctext.getBytes(MetaCatServlet.DEFAULT_ENCODING).length);
307 308
        
308 309
        //submitter
309 310
        Principal p = new Principal();
......
622 623
    private InputStream stringToStream(String s)
623 624
      throws Exception
624 625
    {
625
        ByteArrayInputStream bais = new ByteArrayInputStream(s.getBytes());
626
        ByteArrayInputStream bais = new ByteArrayInputStream(s.getBytes(MetaCatServlet.DEFAULT_ENCODING));
626 627
        return bais;
627 628
    }
628 629
    
src/edu/ucsb/nceas/metacat/DBQuery.java
2005 2005
        byte[] byteString = null;
2006 2006
        ZipEntry zEntry = null;
2007 2007

  
2008
        byteString = docImpl.toString().getBytes();
2008
        byteString = docImpl.getBytes();
2009 2009
        //use docId as the zip entry's name
2010 2010
        zEntry = new ZipEntry(packageZipEntry + "/metadata/"
2011 2011
                + docImpl.getDocID());
......
2230 2230
            }//else
2231 2231
        }//for
2232 2232
        htmlDoc.append("</body></html>");
2233
        byteString = htmlDoc.toString().getBytes();
2233
        // use standard encoding even though the different docs might have use different encodings,
2234
        // the String objects in java should be correct and able to be encoded as the same Metacat default
2235
        byteString = htmlDoc.toString().getBytes(MetaCatServlet.DEFAULT_ENCODING);
2234 2236
        zEntry = new ZipEntry(packageZipEntry + "/metadata.html");
2235 2237
        zEntry.setSize(byteString.length);
2236 2238
        zipOut.putNextEntry(zEntry);

Also available in: Unified diff