001// *************************************************************************************************************************** 002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * 003// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * 004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * 005// * with the License. You may obtain a copy of the License at * 006// * * 007// * http://www.apache.org/licenses/LICENSE-2.0 * 008// * * 009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * 010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * 011// * specific language governing permissions and limitations under the License. * 012// *************************************************************************************************************************** 013package org.apache.juneau.serializer; 014 015import static org.apache.juneau.collections.JsonMap.*; 016import java.lang.annotation.*; 017import java.lang.reflect.*; 018import java.util.*; 019 020import org.apache.juneau.*; 021import org.apache.juneau.collections.*; 022import org.apache.juneau.internal.*; 023import org.apache.juneau.utils.*; 024 025/** 026 * Subclass of {@link Serializer} for byte-based serializers. 027 * 028 * <h5 class='section'>Notes:</h5><ul> 029 * <li class='note'>This class is thread safe and reusable. 030 * </ul> 031 * 032 * <h5 class='section'>See Also:</h5><ul> 033 * <li class='link'><a class="doclink" href="../../../../index.html#jm.SerializersAndParsers">Serializers and Parsers</a> 034 035 * </ul> 036 */ 037public class OutputStreamSerializer extends Serializer { 038 039 //------------------------------------------------------------------------------------------------------------------- 040 // Static 041 //------------------------------------------------------------------------------------------------------------------- 042 043 /** 044 * Creates a new builder for this object. 045 * 046 * @return A new builder. 047 */ 048 public static Builder create() { 049 return new Builder(); 050 } 051 052 //------------------------------------------------------------------------------------------------------------------- 053 // Builder 054 //------------------------------------------------------------------------------------------------------------------- 055 056 /** 057 * Builder class. 058 */ 059 @FluentSetters 060 public static class Builder extends Serializer.Builder { 061 062 BinaryFormat binaryFormat; 063 064 /** 065 * Constructor, default settings. 066 */ 067 protected Builder() { 068 binaryFormat = env("OutputStreamSerializer.binaryFormat", BinaryFormat.HEX); 069 } 070 071 /** 072 * Copy constructor. 073 * 074 * @param copyFrom The bean to copy from. 075 */ 076 protected Builder(OutputStreamSerializer copyFrom) { 077 super(copyFrom); 078 binaryFormat = copyFrom.binaryFormat; 079 } 080 081 /** 082 * Copy constructor. 083 * 084 * @param copyFrom The builder to copy from. 085 */ 086 protected Builder(Builder copyFrom) { 087 super(copyFrom); 088 binaryFormat = copyFrom.binaryFormat; 089 } 090 091 @Override /* Context.Builder */ 092 public Builder copy() { 093 return new Builder(this); 094 } 095 096 @Override /* Context.Builder */ 097 public OutputStreamSerializer build() { 098 return build(OutputStreamSerializer.class); 099 } 100 101 @Override /* Context.Builder */ 102 public HashKey hashKey() { 103 return HashKey.of( 104 super.hashKey(), 105 binaryFormat 106 ); 107 } 108 109 //----------------------------------------------------------------------------------------------------------------- 110 // Properties 111 //----------------------------------------------------------------------------------------------------------------- 112 113 /** 114 * Binary output format. 115 * 116 * <p> 117 * When using the {@link OutputStreamSerializer#serializeToString(Object)} method on stream-based serializers, this defines the format to use 118 * when converting the resulting byte array to a string. 119 * 120 * <h5 class='section'>Example:</h5> 121 * <p class='bjava'> 122 * <jc>// Create a serializer that serializes to BASE64.</jc> 123 * OutputStreamSerializer <jv>serializer</jv> = MsgPackSerializer 124 * .<jsm>create</jsm>() 125 * .binaryFormat(<jsf>BASE64</jsf>) 126 * .build(); 127 * 128 * <jc>// The bean we want to serialize.</jc> 129 * <jk>public class</jk> MyBean {...} 130 * 131 * <jc>// MessagePack will generate BASE64-encoded string.</jc> 132 * String <jv>msgPack</jv> = <jv>serializer</jv>.serializeToString(<jk>new</jk> MyBean()); 133 * </p> 134 * 135 * @param value 136 * The new value for this property. 137 * <br>The default is {@link BinaryFormat#HEX}. 138 * @return This object. 139 */ 140 @FluentSetter 141 public Builder binaryFormat(BinaryFormat value) { 142 binaryFormat = value; 143 return this; 144 } 145 146 // <FluentSetters> 147 148 @Override /* GENERATED - org.apache.juneau.Context.Builder */ 149 public Builder annotations(Annotation...values) { 150 super.annotations(values); 151 return this; 152 } 153 154 @Override /* GENERATED - org.apache.juneau.Context.Builder */ 155 public Builder apply(AnnotationWorkList work) { 156 super.apply(work); 157 return this; 158 } 159 160 @Override /* GENERATED - org.apache.juneau.Context.Builder */ 161 public Builder applyAnnotations(java.lang.Class<?>...fromClasses) { 162 super.applyAnnotations(fromClasses); 163 return this; 164 } 165 166 @Override /* GENERATED - org.apache.juneau.Context.Builder */ 167 public Builder applyAnnotations(Method...fromMethods) { 168 super.applyAnnotations(fromMethods); 169 return this; 170 } 171 172 @Override /* GENERATED - org.apache.juneau.Context.Builder */ 173 public Builder cache(Cache<HashKey,? extends org.apache.juneau.Context> value) { 174 super.cache(value); 175 return this; 176 } 177 178 @Override /* GENERATED - org.apache.juneau.Context.Builder */ 179 public Builder debug() { 180 super.debug(); 181 return this; 182 } 183 184 @Override /* GENERATED - org.apache.juneau.Context.Builder */ 185 public Builder debug(boolean value) { 186 super.debug(value); 187 return this; 188 } 189 190 @Override /* GENERATED - org.apache.juneau.Context.Builder */ 191 public Builder impl(Context value) { 192 super.impl(value); 193 return this; 194 } 195 196 @Override /* GENERATED - org.apache.juneau.Context.Builder */ 197 public Builder type(Class<? extends org.apache.juneau.Context> value) { 198 super.type(value); 199 return this; 200 } 201 202 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 203 public Builder beanClassVisibility(Visibility value) { 204 super.beanClassVisibility(value); 205 return this; 206 } 207 208 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 209 public Builder beanConstructorVisibility(Visibility value) { 210 super.beanConstructorVisibility(value); 211 return this; 212 } 213 214 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 215 public Builder beanContext(BeanContext value) { 216 super.beanContext(value); 217 return this; 218 } 219 220 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 221 public Builder beanContext(BeanContext.Builder value) { 222 super.beanContext(value); 223 return this; 224 } 225 226 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 227 public Builder beanDictionary(java.lang.Class<?>...values) { 228 super.beanDictionary(values); 229 return this; 230 } 231 232 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 233 public Builder beanFieldVisibility(Visibility value) { 234 super.beanFieldVisibility(value); 235 return this; 236 } 237 238 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 239 public Builder beanInterceptor(Class<?> on, Class<? extends org.apache.juneau.swap.BeanInterceptor<?>> value) { 240 super.beanInterceptor(on, value); 241 return this; 242 } 243 244 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 245 public Builder beanMapPutReturnsOldValue() { 246 super.beanMapPutReturnsOldValue(); 247 return this; 248 } 249 250 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 251 public Builder beanMethodVisibility(Visibility value) { 252 super.beanMethodVisibility(value); 253 return this; 254 } 255 256 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 257 public Builder beanProperties(Map<String,Object> values) { 258 super.beanProperties(values); 259 return this; 260 } 261 262 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 263 public Builder beanProperties(Class<?> beanClass, String properties) { 264 super.beanProperties(beanClass, properties); 265 return this; 266 } 267 268 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 269 public Builder beanProperties(String beanClassName, String properties) { 270 super.beanProperties(beanClassName, properties); 271 return this; 272 } 273 274 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 275 public Builder beanPropertiesExcludes(Map<String,Object> values) { 276 super.beanPropertiesExcludes(values); 277 return this; 278 } 279 280 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 281 public Builder beanPropertiesExcludes(Class<?> beanClass, String properties) { 282 super.beanPropertiesExcludes(beanClass, properties); 283 return this; 284 } 285 286 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 287 public Builder beanPropertiesExcludes(String beanClassName, String properties) { 288 super.beanPropertiesExcludes(beanClassName, properties); 289 return this; 290 } 291 292 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 293 public Builder beanPropertiesReadOnly(Map<String,Object> values) { 294 super.beanPropertiesReadOnly(values); 295 return this; 296 } 297 298 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 299 public Builder beanPropertiesReadOnly(Class<?> beanClass, String properties) { 300 super.beanPropertiesReadOnly(beanClass, properties); 301 return this; 302 } 303 304 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 305 public Builder beanPropertiesReadOnly(String beanClassName, String properties) { 306 super.beanPropertiesReadOnly(beanClassName, properties); 307 return this; 308 } 309 310 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 311 public Builder beanPropertiesWriteOnly(Map<String,Object> values) { 312 super.beanPropertiesWriteOnly(values); 313 return this; 314 } 315 316 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 317 public Builder beanPropertiesWriteOnly(Class<?> beanClass, String properties) { 318 super.beanPropertiesWriteOnly(beanClass, properties); 319 return this; 320 } 321 322 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 323 public Builder beanPropertiesWriteOnly(String beanClassName, String properties) { 324 super.beanPropertiesWriteOnly(beanClassName, properties); 325 return this; 326 } 327 328 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 329 public Builder beansRequireDefaultConstructor() { 330 super.beansRequireDefaultConstructor(); 331 return this; 332 } 333 334 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 335 public Builder beansRequireSerializable() { 336 super.beansRequireSerializable(); 337 return this; 338 } 339 340 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 341 public Builder beansRequireSettersForGetters() { 342 super.beansRequireSettersForGetters(); 343 return this; 344 } 345 346 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 347 public Builder dictionaryOn(Class<?> on, java.lang.Class<?>...values) { 348 super.dictionaryOn(on, values); 349 return this; 350 } 351 352 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 353 public Builder disableBeansRequireSomeProperties() { 354 super.disableBeansRequireSomeProperties(); 355 return this; 356 } 357 358 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 359 public Builder disableIgnoreMissingSetters() { 360 super.disableIgnoreMissingSetters(); 361 return this; 362 } 363 364 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 365 public Builder disableIgnoreTransientFields() { 366 super.disableIgnoreTransientFields(); 367 return this; 368 } 369 370 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 371 public Builder disableIgnoreUnknownNullBeanProperties() { 372 super.disableIgnoreUnknownNullBeanProperties(); 373 return this; 374 } 375 376 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 377 public Builder disableInterfaceProxies() { 378 super.disableInterfaceProxies(); 379 return this; 380 } 381 382 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 383 public <T> Builder example(Class<T> pojoClass, T o) { 384 super.example(pojoClass, o); 385 return this; 386 } 387 388 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 389 public <T> Builder example(Class<T> pojoClass, String json) { 390 super.example(pojoClass, json); 391 return this; 392 } 393 394 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 395 public Builder findFluentSetters() { 396 super.findFluentSetters(); 397 return this; 398 } 399 400 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 401 public Builder findFluentSetters(Class<?> on) { 402 super.findFluentSetters(on); 403 return this; 404 } 405 406 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 407 public Builder ignoreInvocationExceptionsOnGetters() { 408 super.ignoreInvocationExceptionsOnGetters(); 409 return this; 410 } 411 412 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 413 public Builder ignoreInvocationExceptionsOnSetters() { 414 super.ignoreInvocationExceptionsOnSetters(); 415 return this; 416 } 417 418 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 419 public Builder ignoreUnknownBeanProperties() { 420 super.ignoreUnknownBeanProperties(); 421 return this; 422 } 423 424 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 425 public Builder ignoreUnknownEnumValues() { 426 super.ignoreUnknownEnumValues(); 427 return this; 428 } 429 430 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 431 public Builder implClass(Class<?> interfaceClass, Class<?> implClass) { 432 super.implClass(interfaceClass, implClass); 433 return this; 434 } 435 436 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 437 public Builder implClasses(Map<Class<?>,Class<?>> values) { 438 super.implClasses(values); 439 return this; 440 } 441 442 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 443 public Builder interfaceClass(Class<?> on, Class<?> value) { 444 super.interfaceClass(on, value); 445 return this; 446 } 447 448 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 449 public Builder interfaces(java.lang.Class<?>...value) { 450 super.interfaces(value); 451 return this; 452 } 453 454 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 455 public Builder locale(Locale value) { 456 super.locale(value); 457 return this; 458 } 459 460 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 461 public Builder mediaType(MediaType value) { 462 super.mediaType(value); 463 return this; 464 } 465 466 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 467 public Builder notBeanClasses(java.lang.Class<?>...values) { 468 super.notBeanClasses(values); 469 return this; 470 } 471 472 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 473 public Builder notBeanPackages(String...values) { 474 super.notBeanPackages(values); 475 return this; 476 } 477 478 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 479 public Builder propertyNamer(Class<? extends org.apache.juneau.PropertyNamer> value) { 480 super.propertyNamer(value); 481 return this; 482 } 483 484 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 485 public Builder propertyNamer(Class<?> on, Class<? extends org.apache.juneau.PropertyNamer> value) { 486 super.propertyNamer(on, value); 487 return this; 488 } 489 490 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 491 public Builder sortProperties() { 492 super.sortProperties(); 493 return this; 494 } 495 496 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 497 public Builder sortProperties(java.lang.Class<?>...on) { 498 super.sortProperties(on); 499 return this; 500 } 501 502 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 503 public Builder stopClass(Class<?> on, Class<?> value) { 504 super.stopClass(on, value); 505 return this; 506 } 507 508 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 509 public <T, S> Builder swap(Class<T> normalClass, Class<S> swappedClass, ThrowingFunction<T,S> swapFunction) { 510 super.swap(normalClass, swappedClass, swapFunction); 511 return this; 512 } 513 514 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 515 public <T, S> Builder swap(Class<T> normalClass, Class<S> swappedClass, ThrowingFunction<T,S> swapFunction, ThrowingFunction<S,T> unswapFunction) { 516 super.swap(normalClass, swappedClass, swapFunction, unswapFunction); 517 return this; 518 } 519 520 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 521 public Builder swaps(java.lang.Class<?>...values) { 522 super.swaps(values); 523 return this; 524 } 525 526 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 527 public Builder timeZone(TimeZone value) { 528 super.timeZone(value); 529 return this; 530 } 531 532 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 533 public Builder typeName(Class<?> on, String value) { 534 super.typeName(on, value); 535 return this; 536 } 537 538 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 539 public Builder typePropertyName(String value) { 540 super.typePropertyName(value); 541 return this; 542 } 543 544 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 545 public Builder typePropertyName(Class<?> on, String value) { 546 super.typePropertyName(on, value); 547 return this; 548 } 549 550 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 551 public Builder useEnumNames() { 552 super.useEnumNames(); 553 return this; 554 } 555 556 @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */ 557 public Builder useJavaBeanIntrospector() { 558 super.useJavaBeanIntrospector(); 559 return this; 560 } 561 562 @Override /* GENERATED - org.apache.juneau.BeanTraverseContext.Builder */ 563 public Builder detectRecursions() { 564 super.detectRecursions(); 565 return this; 566 } 567 568 @Override /* GENERATED - org.apache.juneau.BeanTraverseContext.Builder */ 569 public Builder detectRecursions(boolean value) { 570 super.detectRecursions(value); 571 return this; 572 } 573 574 @Override /* GENERATED - org.apache.juneau.BeanTraverseContext.Builder */ 575 public Builder ignoreRecursions() { 576 super.ignoreRecursions(); 577 return this; 578 } 579 580 @Override /* GENERATED - org.apache.juneau.BeanTraverseContext.Builder */ 581 public Builder ignoreRecursions(boolean value) { 582 super.ignoreRecursions(value); 583 return this; 584 } 585 586 @Override /* GENERATED - org.apache.juneau.BeanTraverseContext.Builder */ 587 public Builder initialDepth(int value) { 588 super.initialDepth(value); 589 return this; 590 } 591 592 @Override /* GENERATED - org.apache.juneau.BeanTraverseContext.Builder */ 593 public Builder maxDepth(int value) { 594 super.maxDepth(value); 595 return this; 596 } 597 598 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 599 public Builder accept(String value) { 600 super.accept(value); 601 return this; 602 } 603 604 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 605 public Builder addBeanTypes() { 606 super.addBeanTypes(); 607 return this; 608 } 609 610 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 611 public Builder addBeanTypes(boolean value) { 612 super.addBeanTypes(value); 613 return this; 614 } 615 616 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 617 public Builder addRootType() { 618 super.addRootType(); 619 return this; 620 } 621 622 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 623 public Builder addRootType(boolean value) { 624 super.addRootType(value); 625 return this; 626 } 627 628 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 629 public Builder keepNullProperties() { 630 super.keepNullProperties(); 631 return this; 632 } 633 634 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 635 public Builder keepNullProperties(boolean value) { 636 super.keepNullProperties(value); 637 return this; 638 } 639 640 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 641 public Builder listener(Class<? extends org.apache.juneau.serializer.SerializerListener> value) { 642 super.listener(value); 643 return this; 644 } 645 646 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 647 public Builder produces(String value) { 648 super.produces(value); 649 return this; 650 } 651 652 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 653 public Builder sortCollections() { 654 super.sortCollections(); 655 return this; 656 } 657 658 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 659 public Builder sortCollections(boolean value) { 660 super.sortCollections(value); 661 return this; 662 } 663 664 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 665 public Builder sortMaps() { 666 super.sortMaps(); 667 return this; 668 } 669 670 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 671 public Builder sortMaps(boolean value) { 672 super.sortMaps(value); 673 return this; 674 } 675 676 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 677 public Builder trimEmptyCollections() { 678 super.trimEmptyCollections(); 679 return this; 680 } 681 682 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 683 public Builder trimEmptyCollections(boolean value) { 684 super.trimEmptyCollections(value); 685 return this; 686 } 687 688 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 689 public Builder trimEmptyMaps() { 690 super.trimEmptyMaps(); 691 return this; 692 } 693 694 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 695 public Builder trimEmptyMaps(boolean value) { 696 super.trimEmptyMaps(value); 697 return this; 698 } 699 700 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 701 public Builder trimStrings() { 702 super.trimStrings(); 703 return this; 704 } 705 706 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 707 public Builder trimStrings(boolean value) { 708 super.trimStrings(value); 709 return this; 710 } 711 712 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 713 public Builder uriContext(UriContext value) { 714 super.uriContext(value); 715 return this; 716 } 717 718 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 719 public Builder uriRelativity(UriRelativity value) { 720 super.uriRelativity(value); 721 return this; 722 } 723 724 @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */ 725 public Builder uriResolution(UriResolution value) { 726 super.uriResolution(value); 727 return this; 728 } 729 730 // </FluentSetters> 731 } 732 733 //------------------------------------------------------------------------------------------------------------------- 734 // Instance 735 //------------------------------------------------------------------------------------------------------------------- 736 737 final BinaryFormat binaryFormat; 738 739 /** 740 * Constructor. 741 * 742 * @param builder 743 * The builder for this object. 744 */ 745 protected OutputStreamSerializer(Builder builder) { 746 super(builder); 747 748 binaryFormat = builder.binaryFormat; 749 } 750 751 @Override /* Context */ 752 public OutputStreamSerializerSession.Builder createSession() { 753 return OutputStreamSerializerSession.create(this); 754 } 755 756 @Override /* Context */ 757 public OutputStreamSerializerSession getSession() { 758 return createSession().build(); 759 } 760 761 @Override /* Serializer */ 762 public final boolean isWriterSerializer() { 763 return false; 764 } 765 766 /** 767 * Convenience method for serializing an object to a <code><jk>byte</jk></code>. 768 * 769 * @param o The object to serialize. 770 * @return The output serialized to a byte array. 771 * @throws SerializeException If a problem occurred trying to convert the output. 772 */ 773 @Override 774 public final byte[] serialize(Object o) throws SerializeException { 775 return getSession().serialize(o); 776 } 777 778 //----------------------------------------------------------------------------------------------------------------- 779 // Properties 780 //----------------------------------------------------------------------------------------------------------------- 781 782 /** 783 * Binary output format. 784 * 785 * @see Builder#binaryFormat(BinaryFormat) 786 * @return 787 * The format to use for the {@link #serializeToString(Object)} method on stream-based serializers when converting byte arrays to strings. 788 */ 789 protected final BinaryFormat getBinaryFormat() { 790 return binaryFormat; 791 } 792 793 //----------------------------------------------------------------------------------------------------------------- 794 // Other methods 795 //----------------------------------------------------------------------------------------------------------------- 796 797 @Override /* Context */ 798 protected JsonMap properties() { 799 return filteredMap("binaryFormat", binaryFormat); 800 } 801}