1 /* 2 (C) Copyright IBM Corp. 2006, 2010 3 4 THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE 5 ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE 6 CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. 7 8 You can obtain a current copy of the Eclipse Public License from 9 http://www.opensource.org/licenses/eclipse-1.0.php 10 11 @author : Endre Bak, ebak@de.ibm.com 12 * 13 * Flag Date Prog Description 14 * ------------------------------------------------------------------------------- 15 * 1565892 2006-10-12 ebak Make SBLIM client JSR48 compliant 16 * 1678807 2007-03-12 ebak Minor CIMDateTime suggestions 17 * 1849235 2008-02-11 blaschke-oss DTStringWriter.writeSigned parameter pDigits is not used 18 * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL 19 * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) 20 * 2989367 2010-04-29 blaschke-oss CIMDateTimeInterval(long) constructor range wrong 21 */ 22 23 package org.metricshub.wbem.sblim.cimclient.internal.cim; 24 25 /*- 26 * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ 27 * WBEM Java Client 28 * ჻჻჻჻჻჻ 29 * Copyright 2023 - 2025 MetricsHub 30 * ჻჻჻჻჻჻ 31 * Licensed under the Apache License, Version 2.0 (the "License"); 32 * you may not use this file except in compliance with the License. 33 * You may obtain a copy of the License at 34 * 35 * http://www.apache.org/licenses/LICENSE-2.0 36 * 37 * Unless required by applicable law or agreed to in writing, software 38 * distributed under the License is distributed on an "AS IS" BASIS, 39 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 40 * See the License for the specific language governing permissions and 41 * limitations under the License. 42 * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ 43 */ 44 45 import java.util.Arrays; 46 47 /** 48 * Class DTStringWriter helps making CIMDateTime Strings. 49 */ 50 public class DTStringWriter { 51 private StringBuffer iBuf = new StringBuffer(); 52 53 /** 54 * writeInt - writes an integer, the upper digits are filled with zeros 55 * 56 * @param pNum 57 * -1 means that asterisks have to be printed 58 * @param pDigits 59 */ 60 public void write(int pDigits, int pNum) { 61 if (pDigits <= 0) return; 62 if (pNum == -1) { 63 char[] cA = new char[pDigits]; 64 Arrays.fill(cA, '*'); 65 this.iBuf.append(cA); 66 return; 67 } 68 String str = Integer.toString(pNum); 69 int paddingDigits = pDigits - str.length(); 70 if (paddingDigits > 0) { 71 char[] cA = new char[paddingDigits]; 72 Arrays.fill(cA, '0'); 73 this.iBuf.append(cA).append(str); 74 } else this.iBuf.append(str); 75 } 76 77 /** 78 * writeSignedInt - used for utc writing 79 * 80 * @param pNum 81 * @param pDigits 82 */ 83 public void writeSigned(int pDigits, int pNum) { 84 char sign; 85 if (pNum < 0) { 86 sign = '-'; 87 pNum = -pNum; 88 } else sign = '+'; 89 write(sign); 90 write(pDigits, pNum); 91 } 92 93 /** 94 * writeUSec 95 * 96 * @param pUSec 97 * @param pUnsignificantDigits 98 */ 99 public void writeUSec(int pUSec, int pUnsignificantDigits) { 100 int digits = 6 - pUnsignificantDigits; 101 write(digits, pUSec); 102 for (int i = 0; i < pUnsignificantDigits; i++) write('*'); 103 } 104 105 /** 106 * writeChar 107 * 108 * @param pChar 109 */ 110 public void write(char pChar) { 111 this.iBuf.append(pChar); 112 } 113 114 /** 115 * write 116 * 117 * @param pStr 118 */ 119 public void write(String pStr) { 120 this.iBuf.append(pStr); 121 } 122 123 /** 124 * @see java.lang.Object#toString() 125 */ 126 @Override 127 public String toString() { 128 return this.iBuf.toString(); 129 } 130 }