1
1
/*
2
- * Copyright 2002-2013 the original author or authors.
2
+ * Copyright 2002-2015 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -71,7 +71,7 @@ public class MockHttpServletResponse implements HttpServletResponse {
71
71
72
72
private boolean charset = false ;
73
73
74
- private final ByteArrayOutputStream content = new ByteArrayOutputStream ();
74
+ private final ByteArrayOutputStream content = new ByteArrayOutputStream (1024 );
75
75
76
76
private final ServletOutputStream outputStream = new ResponseServletOutputStream (this .content );
77
77
@@ -189,8 +189,8 @@ public byte[] getContentAsByteArray() {
189
189
190
190
public String getContentAsString () throws UnsupportedEncodingException {
191
191
flushBuffer ();
192
- return (this .characterEncoding != null ) ?
193
- this .content .toString (this .characterEncoding ) : this .content .toString ();
192
+ return (this .characterEncoding != null ?
193
+ this .content .toString (this .characterEncoding ) : this .content .toString ()) ;
194
194
}
195
195
196
196
@ Override
@@ -218,8 +218,7 @@ public void setContentType(String contentType) {
218
218
if (contentType != null ) {
219
219
int charsetIndex = contentType .toLowerCase ().indexOf (CHARSET_PREFIX );
220
220
if (charsetIndex != -1 ) {
221
- String encoding = contentType .substring (charsetIndex + CHARSET_PREFIX .length ());
222
- this .characterEncoding = encoding ;
221
+ this .characterEncoding = contentType .substring (charsetIndex + CHARSET_PREFIX .length ());
223
222
this .charset = true ;
224
223
}
225
224
updateContentTypeHeader ();
@@ -416,11 +415,13 @@ public String encodeRedirectURL(String url) {
416
415
}
417
416
418
417
@ Override
418
+ @ Deprecated
419
419
public String encodeUrl (String url ) {
420
420
return encodeURL (url );
421
421
}
422
422
423
423
@ Override
424
+ @ Deprecated
424
425
public String encodeRedirectUrl (String url ) {
425
426
return encodeRedirectURL (url );
426
427
}
@@ -505,11 +506,12 @@ private void addHeaderValue(String name, Object value) {
505
506
506
507
private boolean setSpecialHeader (String name , Object value ) {
507
508
if (CONTENT_TYPE_HEADER .equalsIgnoreCase (name )) {
508
- setContentType (( String ) value );
509
+ setContentType (value . toString () );
509
510
return true ;
510
511
}
511
512
else if (CONTENT_LENGTH_HEADER .equalsIgnoreCase (name )) {
512
- setContentLength (Integer .parseInt ((String ) value ));
513
+ setContentLength (value instanceof Number ? ((Number ) value ).intValue () :
514
+ Integer .parseInt (value .toString ()));
513
515
return true ;
514
516
}
515
517
else {
@@ -534,14 +536,15 @@ private void doAddHeaderValue(String name, Object value, boolean replace) {
534
536
535
537
@ Override
536
538
public void setStatus (int status ) {
537
- if (!this .isCommitted ()) {
539
+ if (!this .isCommitted ()) {
538
540
this .status = status ;
539
541
}
540
542
}
541
543
542
544
@ Override
545
+ @ Deprecated
543
546
public void setStatus (int status , String errorMessage ) {
544
- if (!this .isCommitted ()) {
547
+ if (!this .isCommitted ()) {
545
548
this .status = status ;
546
549
this .errorMessage = errorMessage ;
547
550
}
0 commit comments