| | |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.IOException; |
| | | import java.io.PrintStream; |
| | | |
| | | import org.opends.server.protocols.asn1.ASN1OctetString; |
| | | import org.opends.server.protocols.ldap.LDAPControl; |
| | |
| | | * |
| | | * @param argString The argument string containing the encoded control |
| | | * information. |
| | | * @param err A print stream to which error messages should be |
| | | * written if a problem occurs. |
| | | * |
| | | * @return The control decoded from the provided string, or <CODE>null</CODE> |
| | | * if an error occurs while parsing the argument value. |
| | | */ |
| | | public static LDAPControl getControl(String argString) |
| | | public static LDAPControl getControl(String argString, PrintStream err) |
| | | { |
| | | LDAPControl control = null; |
| | | String controlOID = null; |
| | |
| | | controlCriticality = false; |
| | | } else |
| | | { |
| | | System.err.println("Invalid format for criticality value:" + remainder); |
| | | err.println("Invalid format for criticality value:" + remainder); |
| | | return null; |
| | | } |
| | | control = new LDAPControl(controlOID, controlCriticality); |
| | |
| | | controlCriticality = false; |
| | | } else |
| | | { |
| | | System.err.println("Invalid format for criticality value:" + critical); |
| | | err.println("Invalid format for criticality value:" + critical); |
| | | return null; |
| | | } |
| | | |
| | |
| | | } else if(valString.charAt(0) == '<') |
| | | { |
| | | // Read data from the file. |
| | | String fileURL = valString.substring(1, valString.length()); |
| | | String filePath = valString.substring(1, valString.length()); |
| | | try |
| | | { |
| | | byte[] val = readBytesFromFile(fileURL); |
| | | byte[] val = readBytesFromFile(filePath, err); |
| | | controlValue = new ASN1OctetString(val); |
| | | } |
| | | catch (Exception e) |
| | |
| | | /** |
| | | * Read the data from the specified file and return it in a byte array. |
| | | * |
| | | * @param filePath The path to the file that should be read. |
| | | * @param filePath The path to the file that should be read. |
| | | * @param err A print stream to which error messages should be |
| | | * written if a problem occurs. |
| | | * |
| | | * @return A byte array containing the contents of the requested file. |
| | | * |
| | | * @throws IOException If a problem occurs while trying to read the |
| | | * specified file. |
| | | */ |
| | | public static byte[] readBytesFromFile(String filePath) |
| | | public static byte[] readBytesFromFile(String filePath, PrintStream err) |
| | | throws IOException |
| | | { |
| | | byte[] val = null; |
| | |
| | | // Ensure all the bytes have been read in |
| | | if (offset < val.length) |
| | | { |
| | | System.err.println("Could not completely read file "+filePath); |
| | | err.println("Could not completely read file "+filePath); |
| | | return null; |
| | | } |
| | | |