< prev index next >

src/java.naming/share/classes/javax/naming/ldap/Rdn.java

Print this page


   1 /*
   2  * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 718             if (len == utf8.length) {
 719                 return utf8;
 720             } else {
 721                 byte[] res = new byte[len];
 722                 System.arraycopy(utf8, 0, res, 0, len);
 723                 return res;
 724             }
 725         }
 726 
 727     /*
 728      * Best guess as to what RFC 2253 means by "whitespace".
 729      */
 730     private static boolean isWhitespace(char c) {
 731         return (c == ' ' || c == '\r');
 732     }
 733 
 734     /**
 735      * Serializes only the unparsed RDN, for compactness and to avoid
 736      * any implementation dependency.
 737      *
 738      * @serialData      The RDN string



 739      */

 740     private void writeObject(ObjectOutputStream s)
 741             throws java.io.IOException {
 742         s.defaultWriteObject();
 743         s.writeObject(toString());
 744     }
 745 











 746     private void readObject(ObjectInputStream s)
 747             throws IOException, ClassNotFoundException {
 748         s.defaultReadObject();
 749         entries = new ArrayList<>(DEFAULT_SIZE);
 750         String unparsed = (String) s.readObject();
 751         try {
 752             (new Rfc2253Parser(unparsed)).parseRdn(this);
 753         } catch (InvalidNameException e) {
 754             // shouldn't happen
 755             throw new java.io.StreamCorruptedException(
 756                     "Invalid name: " + unparsed);
 757         }
 758     }
 759 }
   1 /*
   2  * Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 718             if (len == utf8.length) {
 719                 return utf8;
 720             } else {
 721                 byte[] res = new byte[len];
 722                 System.arraycopy(utf8, 0, res, 0, len);
 723                 return res;
 724             }
 725         }
 726 
 727     /*
 728      * Best guess as to what RFC 2253 means by "whitespace".
 729      */
 730     private static boolean isWhitespace(char c) {
 731         return (c == ' ' || c == '\r');
 732     }
 733 
 734     /**
 735      * Serializes only the unparsed RDN, for compactness and to avoid
 736      * any implementation dependency.
 737      *
 738      * @serialData The unparsed RDN {@code String} representation.
 739      *
 740      * @param s the {@code ObjectOutputStream} to write to
 741      * @throws java.io.IOException if an I/O error occurs.
 742      */
 743     @java.io.Serial
 744     private void writeObject(ObjectOutputStream s)
 745             throws java.io.IOException {
 746         s.defaultWriteObject();
 747         s.writeObject(toString());
 748     }
 749 
 750     /**
 751      * Initializes the {@code Rdn} from deserialized data.
 752      *
 753      * See {@code writeObject} for a description of the serial form.
 754      *
 755      * @param s the {@code ObjectInputStream} to read from
 756      * @throws IOException if an I/O error occurs.
 757      * @throws ClassNotFoundException if the class of a serialized object
 758      *         could not be found.
 759      */
 760     @java.io.Serial
 761     private void readObject(ObjectInputStream s)
 762             throws IOException, ClassNotFoundException {
 763         s.defaultReadObject();
 764         entries = new ArrayList<>(DEFAULT_SIZE);
 765         String unparsed = (String) s.readObject();
 766         try {
 767             (new Rfc2253Parser(unparsed)).parseRdn(this);
 768         } catch (InvalidNameException e) {
 769             // shouldn't happen
 770             throw new java.io.StreamCorruptedException(
 771                     "Invalid name: " + unparsed);
 772         }
 773     }
 774 }
< prev index next >