Class Utilities

ユーティリティ

このサービスは、文字列のエンコード/デコード、日付の書式設定、JSON 操作、その他のタスクのユーティリティを提供します。

プロパティ

プロパティ種類説明
CharsetCharset
DigestAlgorithmDigestAlgorithm
MacAlgorithmMacAlgorithm
RsaAlgorithmRsaAlgorithm

Methods

メソッド戻り値の型概要
base64Decode(encoded)Byte[]base-64 でエンコードされた文字列を UTF-8 バイト配列にデコードします。
base64Decode(encoded, charset)Byte[]Base64 でエンコードされた文字列を、特定の文字セットのバイト配列にデコードします。
base64DecodeWebSafe(encoded)Byte[]ウェブセーフな Base64 でエンコードされた文字列を UTF-8 バイト配列にデコードします。
base64DecodeWebSafe(encoded, charset)Byte[]ウェブセーフな Base64 でエンコードされた文字列を、特定の文字セットのバイト配列にデコードします。
base64Encode(data)String指定されたバイト配列から Base64 でエンコードされた文字列を生成します。
base64Encode(data)String指定された文字列から Base64 でエンコードされた文字列を生成します。
base64Encode(data, charset)String指定された文字セットの文字列から、Base64 でエンコードされた文字列を生成します。
base64EncodeWebSafe(data)String指定されたバイト配列から、ウェブセーフな Base64 でエンコードされた文字列を生成します。
base64EncodeWebSafe(data)String指定された文字列から、ウェブセーフな Base64 でエンコードされた文字列を生成します。
base64EncodeWebSafe(data, charset)String特定の文字セット内の指定された文字列から、ウェブセーフな Base64 エンコード文字列を生成します。
computeDigest(algorithm, value)Byte[]指定された Byte[] 値に対して、指定されたアルゴリズムを使用してダイジェストを計算します。
computeDigest(algorithm, value)Byte[]指定された String 値に対して、指定されたアルゴリズムを使用してダイジェストを計算します。
computeDigest(algorithm, value, charset)Byte[]指定された文字セットを使用し、指定された String 値に対して指定されたアルゴリズムを使用してダイジェストを計算します。
computeHmacSha256Signature(value, key)Byte[]指定された鍵で HMAC-SHA256 を使用して指定された値に署名します。
computeHmacSha256Signature(value, key)Byte[]指定された鍵で HMAC-SHA256 を使用して指定された値に署名します。
computeHmacSha256Signature(value, key, charset)Byte[]指定されたキーと文字セットで HMAC-SHA256 を使用して指定された値に署名します。
computeHmacSignature(algorithm, value, key)Byte[]指定された Key-Value に指定されたアルゴリズムを使用して、メッセージ認証コードを計算します。
computeHmacSignature(algorithm, value, key)Byte[]指定された Key-Value に指定されたアルゴリズムを使用して、メッセージ認証コードを計算します。
computeHmacSignature(algorithm, value, key, charset)Byte[]指定された Key-Value に指定されたアルゴリズムを使用して、メッセージ認証コードを計算します。
computeRsaSha1Signature(value, key)Byte[]指定された鍵で RSA-SHA1 を使用して、指定された値に署名します。
computeRsaSha1Signature(value, key, charset)Byte[]指定された鍵と文字セットで RSA-SHA1 を使用して、指定された値に署名します。
computeRsaSha256Signature(value, key)Byte[]指定された鍵で RSA-SHA256 を使用して、指定された値に署名します。
computeRsaSha256Signature(value, key, charset)Byte[]指定された鍵で RSA-SHA256 を使用して、指定された値に署名します。
computeRsaSignature(algorithm, value, key)Byte[]指定された RSA アルゴリズムと指定された鍵を使用して、指定された値に署名します。
computeRsaSignature(algorithm, value, key, charset)Byte[]指定された鍵と文字セットにより、指定された RSA アルゴリズムを使用して、指定された値に署名します。
formatDate(date, timeZone, format)StringJava SE SimpleDateFormat クラスの仕様に従って日付をフォーマットします。
formatString(template, args)String「%」スタイルのフォーマット文字列を使用して、sprintf に似た文字列フォーマットを実行します。
getUuid()StringUUID を文字列として取得します(java.util.UUID.randomUUID() メソッドを使用する場合と同等です)。
gzip(blob)Blob指定された Blob データを gzip で圧縮し、新しい Blob オブジェクトに返します。
gzip(blob, name)Blob指定された Blob データを gzip で圧縮し、新しい Blob オブジェクトに返します。
newBlob(data)Blobバイト配列から新しい Blob オブジェクトを作成します。
newBlob(data, contentType)Blobバイト配列とコンテンツ タイプから新しい Blob オブジェクトを作成します。
newBlob(data, contentType, name)Blobバイト配列、コンテンツ タイプ、名前から新しい Blob オブジェクトを作成します。
newBlob(data)Blob文字列から新しい Blob オブジェクトを作成します。
newBlob(data, contentType)Blob文字列とコンテンツ タイプから新しい Blob オブジェクトを作成します。
newBlob(data, contentType, name)Blob文字列、コンテンツ タイプ、名前から新しい Blob オブジェクトを作成します。
parseCsv(csv)String[][]CSV 文字列の表形式の 2D 配列表現を返します。
parseCsv(csv, delimiter)String[][]カスタムの区切り文字を使用して、CSV 文字列の表形式の 2D 配列表現を返します。
parseDate(date, timeZone, format)Date提供された文字列の日付を、Java Standard Edition SimpleDateFormat クラスの仕様に従って解析します。
sleep(milliseconds)void指定したミリ秒数だけスリープします。
ungzip(blob)BlobBlob オブジェクトを圧縮解除し、非圧縮データを含む Blob を返します。
unzip(blob)Blob[]zip ファイルを表す Blob を取得し、そのコンポーネント ファイルを返します。
zip(blobs)Blob渡された Blob のデータを含む ZIP ファイルである新しい Blob オブジェクトを作成します。
zip(blobs, name)Blob渡された Blob のデータを含む ZIP ファイルである新しい Blob オブジェクトを作成します。

詳細なドキュメント

base64Decode(encoded)

base-64 でエンコードされた文字列を UTF-8 バイト配列にデコードします。

// This is the base64 encoded form of "Google グループ"
var base64data = "R29vZ2xlIOOCsOODq+ODvOODlw==";

// This logs:
//     [71, 111, 111, 103, 108, 101, 32, -29, -126, -80,
//      -29, -125, -85, -29, -125, -68, -29, -125, -105]
var decoded = Utilities.base64Decode(base64data);
Logger.log(decoded);

// If we want a String instead of a byte array:
// This logs the original "Google グループ"
Logger.log(Utilities.newBlob(decoded).getDataAsString());

パラメータ

名前説明
encodedStringデコードするデータのバイトの配列。

リターン

Byte[] - base-64 でエンコードされた引数でバイト配列として表される元データ。


base64Decode(encoded, charset)

Base64 でエンコードされた文字列を、特定の文字セットのバイト配列にデコードします。

// This is the base64 encoded form of "Google グループ"
var base64data = "R29vZ2xlIOOCsOODq+ODvOODlw==";

var decoded = Utilities.base64Decode(base64data, Utilities.Charset.UTF_8);

// This logs:
//     [71, 111, 111, 103, 108, 101, 32, -29, -126, -80,
//      -29, -125, -85, -29, -125, -68, -29, -125, -105]
Logger.log(decoded);

// If we want a String instead of a byte array:
// This logs the original "Google グループ"
Logger.log(Utilities.newBlob(decoded).getDataAsString());

パラメータ

名前説明
encodedStringデコードするデータの文字列。
charsetCharset入力の文字セットを指定する Charset

リターン

Byte[] - base-64 でエンコードされた引数でバイト配列として表される元データ。


base64DecodeWebSafe(encoded)

ウェブセーフな Base64 でエンコードされた文字列を UTF-8 バイト配列にデコードします。

// This is the base64 web-safe encoded form of "Google グループ"
var base64data = "R29vZ2xlIOOCsOODq-ODvOODlw==";

var decoded = Utilities.base64DecodeWebSafe(base64data);

// This logs:
//     [71, 111, 111, 103, 108, 101, 32, -29, -126, -80,
//      -29, -125, -85, -29, -125, -68, -29, -125, -105]
Logger.log(decoded);

// If we want a String instead of a byte array:
// This logs the original "Google グループ"
Logger.log(Utilities.newBlob(decoded).getDataAsString());

パラメータ

名前説明
encodedStringデコードするウェブセーフ データのバイトの配列。

リターン

Byte[] - ウェブセーフな Base64 でエンコードされた引数で、バイト配列として表される元データ。


base64DecodeWebSafe(encoded, charset)

ウェブセーフな Base64 でエンコードされた文字列を、特定の文字セットのバイト配列にデコードします。

// This is the base64 web-safe encoded form of "Google グループ"
var base64data = "R29vZ2xlIOOCsOODq-ODvOODlw==";

var decoded = Utilities.base64DecodeWebSafe(base64data, Utilities.Charset.UTF_8);

// This logs:
//     [71, 111, 111, 103, 108, 101, 32, -29, -126, -80,
//      -29, -125, -85, -29, -125, -68, -29, -125, -105]
Logger.log(decoded);

// If we want a String instead of a byte array:
// This logs the original "Google グループ"
Logger.log(Utilities.newBlob(decoded).getDataAsString());

パラメータ

名前説明
encodedStringデコードするウェブセーフなデータの文字列。
charsetCharset入力の文字セットを指定する Charset

リターン

Byte[] - ウェブセーフな Base64 でエンコードされた引数で、バイト配列として表される元データ。


base64Encode(data)

指定されたバイト配列から Base64 でエンコードされた文字列を生成します。Base64 は、バイナリデータを受け入れられないさまざまなツールに受け入れられている一般的なエンコードです。Base64 はメール、HTTP、XML ドキュメントなどのインターネット プロトコルでよく使用されています。

// Instantiates a blob here for clarity
var blob = Utilities.newBlob("A string here");

// Writes 'QSBzdHJpbmcgaGVyZQ==' to the log.
var encoded = Utilities.base64Encode(blob.getBytes());
Logger.log(encoded);

パラメータ

名前説明
dataByte[]エンコードするデータの byte[]。

リターン

String - 渡されたデータの base-64 エンコード表現。


base64Encode(data)

指定された文字列から Base64 でエンコードされた文字列を生成します。Base64 は、バイナリデータを受け入れられないさまざまなツールに受け入れられる一般的なエンコードです。Base64 はメール、HTTP、XML ドキュメントなどのインターネット プロトコルでよく使用されています。

// Writes 'QSBzdHJpbmcgaGVyZQ==' to the log.
var encoded = Utilities.base64Encode("A string here");
Logger.log(encoded);

パラメータ

名前説明
dataStringエンコードする文字列。

リターン

String - 入力文字列を Base64 でエンコードした表現。


base64Encode(data, charset)

指定された文字セットの文字列から、Base64 でエンコードされた文字列を生成します。文字セットは、エンコード可能な文字のエンコード方法です。これらは通常、バイナリ形式で行われますが、通常は特定のデータ転送プロトコルと互換性がない可能性があります。データの互換性を確保するために、通常は Base64 にエンコードされます。これは、バイナリデータを受け入れられないさまざまなツールに受け入れられている一般的なエンコードです。Base64 はメール、HTTP、XML ドキュメントなどのインターネット プロトコルでよく使用されています。

// "Google Groups" in Katakana (Japanese)
var input = "Google グループ";

// Writes "R29vZ2xlIOOCsOODq+ODvOODlw==" to the log
var encoded = Utilities.base64Encode(input, Utilities.Charset.UTF_8);
Logger.log(encoded);

パラメータ

名前説明
dataStringエンコードするデータの文字列。
charsetCharset入力の文字セットを指定する Charset

リターン

String - 指定された Charset で入力文字列を Base64 エンコードしたもの。


base64EncodeWebSafe(data)

指定されたバイト配列から、ウェブセーフな Base64 でエンコードされた文字列を生成します。Base64 は、バイナリデータを受け入れられないさまざまなツールに受け入れられる一般的なエンコードです。Base64 ウェブセーフは、メール、HTTP、XML ドキュメントなどのインターネット プロトコルでよく使用されています。

// Instantiates a blob here for clarity
var blob = Utilities.newBlob("A string here");

// Writes 'QSBzdHJpbmcgaGVyZQ==' to the log.
var encoded = Utilities.base64EncodeWebSafe(blob.getBytes());
Logger.log(encoded);

パラメータ

名前説明
dataByte[]エンコードするデータのバイトの配列。

リターン

String - 渡されたデータの Base64 ウェブセーフ エンコード表現。


base64EncodeWebSafe(data)

指定された文字列から、ウェブセーフな Base64 でエンコードされた文字列を生成します。Base64 は、バイナリデータを受け入れられないさまざまなツールに受け入れられている一般的なエンコードです。Base64 ウェブセーフは、メール、HTTP、XML ドキュメントなどのインターネット プロトコルでよく使用されています。

// Writes 'QSBzdHJpbmcgaGVyZQ==' to the log.
var encoded = Utilities.base64EncodeWebSafe("A string here");
Logger.log(encoded);

パラメータ

名前説明
dataStringエンコードする文字列。

リターン

String - 入力文字列のウェブセーフな Base64 エンコード表現。


base64EncodeWebSafe(data, charset)

特定の文字セットの指定された文字列から、ウェブセーフな Base64 エンコード文字列を生成します。 文字セットは、エンコード可能な文字をエンコードする方法です。これらは通常、バイナリ形式で行われますが、これは通常、特定のデータ転送プロトコルと互換性がない場合があります。データの互換性を確保するために、通常は Base64 にエンコードされます。これは、バイナリデータを受け入れられないさまざまなツールに受け入れられる一般的なエンコードです。Base64 ウェブセーフは、メール、HTTP、XML ドキュメントなどのインターネット プロトコルでよく使用されています。

// "Google Groups" in Katakana (Japanese)
var input = "Google グループ";

// Writes "R29vZ2xlIOOCsOODq-ODvOODlw==" to the log
var encoded = Utilities.base64EncodeWebSafe(input, Utilities.Charset.UTF_8);
Logger.log(encoded);

パラメータ

名前説明
dataStringエンコードするデータの文字列。
charsetCharset入力の文字セットを指定する Charset

リターン

String - 指定された Charset での入力文字列の、ウェブセーフな Base64 エンコード表現。


computeDigest(algorithm, value)

指定された Byte[] 値に対して、指定されたアルゴリズムを使用してダイジェストを計算します。

var input = Utilities.base64Decode("aW5wdXQgdG8gaGFzaA0K") // == base64encode("input to hash")
var digest = Utilities.computeDigest(Utilities.DigestAlgorithm.MD5, input);
Logger.log(digest);

パラメータ

名前説明
algorithmDigestAlgorithm使用する DigestAlgorithm
valueByte[]ダイジェストを計算する入力文字列値。

リターン

Byte[] - 出力ダイジェストを表す byte[]。


computeDigest(algorithm, value)

指定された String 値に対して、指定されたアルゴリズムを使用してダイジェストを計算します。

var digest = Utilities.computeDigest(Utilities.DigestAlgorithm.MD5, "input to hash");
Logger.log(digest);

パラメータ

名前説明
algorithmDigestAlgorithm使用する DigestAlgorithm
valueStringダイジェストを計算する入力文字列値。

リターン

Byte[] - 出力ダイジェストを表す byte[]。


computeDigest(algorithm, value, charset)

指定された文字セットを使用し、指定された String 値に対して指定されたアルゴリズムを使用してダイジェストを計算します。

var digest = Utilities.computeDigest(Utilities.DigestAlgorithm.MD5,
                                     "input to hash",
                                     Utilities.Charset.US_ASCII);
Logger.log(digest);

パラメータ

名前説明
algorithmDigestAlgorithm使用する DigestAlgorithm
valueStringダイジェストを計算する入力文字列値。
charsetCharset入力文字セットを表す Charset

リターン

Byte[] - 出力ダイジェストを表す byte[]。


computeHmacSha256Signature(value, key)

指定された鍵で HMAC-SHA256 を使用して指定された値に署名します。

// This writes an array of bytes to the log.
var input = Utilities.base64Decode("aW5wdXQgdG8gaGFzaA0K") // == base64encode("input to hash")
var key = Utilities.base64Decode("a2V5"); // == base64encode("key")
var signature = Utilities.computeHmacSha256Signature(input, key);
Logger.log(signature);

パラメータ

名前説明
valueByte[]ハッシュを生成する入力値。
keyByte[]ハッシュの生成に使用するキー。

リターン

Byte[] - 出力署名を表す byte[]。


computeHmacSha256Signature(value, key)

指定された鍵で HMAC-SHA256 を使用して指定された値に署名します。

// This writes an array of bytes to the log.
var signature = Utilities.computeHmacSha256Signature("this is my input",
                                                      "my key - use a stronger one");
Logger.log(signature);

パラメータ

名前説明
valueStringハッシュを生成する入力値。
keyStringハッシュの生成に使用するキー。

リターン

Byte[] - 出力署名を表す byte[]。


computeHmacSha256Signature(value, key, charset)

指定されたキーと文字セットで、HMAC-SHA256 を使用して指定された値に署名します。

// This writes an array of bytes to the log.
var signature = Utilities.computeHmacSha256Signature("this is my input",
                                                     "my key - use a stronger one",
                                                     Utilities.Charset.US_ASCII);
Logger.log(signature);

パラメータ

名前説明
valueStringハッシュを生成する入力値。
keyStringハッシュの生成に使用するキー。
charsetCharset入力文字セットを表す Charset

リターン

Byte[] - 出力署名を表す byte[]。


computeHmacSignature(algorithm, value, key)

指定された Key-Value に指定されたアルゴリズムを使用して、メッセージ認証コードを計算します。

// This writes an array of bytes to the log.
var input = Utilities.base64Decode("aW5wdXQgdG8gaGFzaA0K") // == base64encode("input to hash")
var key = Utilities.base64Decode("a2V5"); // == base64encode("key")
var signature = Utilities.computeHmacSignature(Utilities.MacAlgorithm.HMAC_MD5, input, key);
Logger.log(signature);

パラメータ

名前説明
algorithmMacAlgorithm入力値のハッシュに使用する MacAlgorithm アルゴリズム。
valueByte[]ハッシュを生成する入力値。
keyByte[]ハッシュの生成に使用するキー。

リターン

Byte[] - 出力署名を表す byte[]。


computeHmacSignature(algorithm, value, key)

指定された Key-Value に指定されたアルゴリズムを使用して、メッセージ認証コードを計算します。

// This writes an array of bytes to the log.
var signature = Utilities.computeHmacSignature(Utilities.MacAlgorithm.HMAC_MD5,
                                               "input to hash",
                                               "key");
Logger.log(signature);

パラメータ

名前説明
algorithmMacAlgorithm入力値のハッシュに使用する MacAlgorithm アルゴリズム。
valueStringハッシュを生成する入力値。
keyStringハッシュの生成に使用するキー。

リターン

Byte[] - 出力署名を表す byte[]。


computeHmacSignature(algorithm, value, key, charset)

指定された Key-Value に指定されたアルゴリズムを使用して、メッセージ認証コードを計算します。

// This writes an array of bytes to the log.
var signature = Utilities.computeHmacSignature(Utilities.MacAlgorithm.HMAC_MD5,
                                               "input to hash",
                                               "key",
                                               Utilities.Charset.US_ASCII);
Logger.log(signature);

パラメータ

名前説明
algorithmMacAlgorithm入力値のハッシュに使用する MacAlgorithm アルゴリズム。
valueStringハッシュを生成する入力値。
keyStringハッシュの生成に使用するキー。
charsetCharset入力文字セットを表す Charset

リターン

Byte[] - 出力署名を表す byte[]。


computeRsaSha1Signature(value, key)

指定された鍵で RSA-SHA1 を使用して、指定された値に署名します。

// This writes an array of bytes to the log.
var signature = Utilities.computeRsaSha1Signature("this is my input",
    "-----BEGIN PRIVATE KEY-----\nprivatekeyhere\n-----END PRIVATE KEY-----\n");
Logger.log(signature);

パラメータ

名前説明
valueStringハッシュを生成する入力値。
keyString署名の生成に使用する PEM 形式の鍵。

リターン

Byte[] - 出力署名を表す byte[]。


computeRsaSha1Signature(value, key, charset)

指定された鍵と文字セットで RSA-SHA1 を使用し、指定された値に署名します。

// This writes an array of bytes to the log.
var signature = Utilities.computeRsaSha1Signature("this is my input",
    "-----BEGIN PRIVATE KEY-----\nprivatekeyhere\n-----END PRIVATE KEY-----\n"
    Utilities.Charset.US_ASCII);
Logger.log(signature);

パラメータ

名前説明
valueStringハッシュを生成する入力値。
keyString署名の生成に使用する PEM 形式の鍵。
charsetCharset入力文字セットを表す Charset

リターン

Byte[] - 出力署名を表す byte[]。


computeRsaSha256Signature(value, key)

指定された鍵で RSA-SHA256 を使用して、指定された値に署名します。

// This writes an array of bytes to the log.
var signature = Utilities.computeRsaSha256Signature("this is my input",
    "-----BEGIN PRIVATE KEY-----\nprivatekeyhere\n-----END PRIVATE KEY-----\n");
Logger.log(signature);

パラメータ

名前説明
valueStringハッシュを生成する入力値。
keyString署名の生成に使用する PEM 形式の鍵。

リターン

Byte[] - 出力署名を表す byte[]。


computeRsaSha256Signature(value, key, charset)

指定された鍵で RSA-SHA256 を使用して、指定された値に署名します。

// This writes an array of bytes to the log.
var signature = Utilities.computeRsaSha256Signature("this is my input",
    "-----BEGIN PRIVATE KEY-----\nprivatekeyhere\n-----END PRIVATE KEY-----\n");
Logger.log(signature);

パラメータ

名前説明
valueStringハッシュを生成する入力値。
keyString署名の生成に使用する PEM 形式の鍵。
charsetCharset入力文字セットを表す Charset

リターン

Byte[] - 出力署名を表す byte[]。


computeRsaSignature(algorithm, value, key)

指定された RSA アルゴリズムと指定された鍵を使用して、指定された値に署名します。

// This writes an array of bytes to the log.
var signature = Utilities.computeRsaSignature(Utilities.RsaAlgorithm.RSA_SHA_256,
    "this is my input",
    "-----BEGIN PRIVATE KEY-----\nprivatekeyhere\n-----END PRIVATE KEY-----\n");
Logger.log(signature);

パラメータ

名前説明
algorithmRsaAlgorithm入力値のハッシュに使用する RsaAlgorithm アルゴリズム。
valueStringハッシュを生成する入力値。
keyString署名の生成に使用する PEM 形式の鍵。

リターン

Byte[] - 出力署名を表す byte[]。


computeRsaSignature(algorithm, value, key, charset)

指定された鍵と文字セットで、指定された RSA アルゴリズムを使用して、指定された値に署名します。

// This writes an array of bytes to the log.
var signature = Utilities.computeRsaSignature(Utilities.RsaAlgorithm.RSA_SHA_256,
    "this is my input",
    "-----BEGIN PRIVATE KEY-----\nprivatekeyhere\n-----END PRIVATE KEY-----\n",
    Utilities.Charset.US_ASCII);
Logger.log(signature);

パラメータ

名前説明
algorithmRsaAlgorithm入力値のハッシュに使用する RsaAlgorithm アルゴリズム。
valueStringハッシュを生成する入力値。
keyString署名の生成に使用する PEM 形式の鍵。
charsetCharset入力文字セットを表す Charset

リターン

Byte[] - 出力署名を表す byte[]。


formatDate(date, timeZone, format)

Java SE SimpleDateFormat クラスの仕様に従って日付をフォーマットします。この仕様については、 http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html をご覧ください。

// This formats the date as Greenwich Mean Time in the format
// year-month-dateThour-minute-second.
var formattedDate = Utilities.formatDate(new Date(), "GMT", "yyyy-MM-dd'T'HH:mm:ss'Z'");
Logger.log(formattedDate);

パラメータ

名前説明
dateDate文字列としてフォーマットする Date
timeZoneString結果の出力タイムゾーン。
formatStringSimpleDateFormat 仕様の形式。

リターン

String - 書式設定された文字列で表される入力日付。


formatString(template, args)

「%」形式の形式文字列を使用して、sprintf に似た文字列の書式設定を行います。

// " 123.456000"
Utilities.formatString('%11.6f', 123.456);

// "   abc"
Utilities.formatString('%6s', 'abc');

パラメータ

名前説明
templateString何が返されるかを制御するフォーマット文字列。
argsObject...テンプレートの「%」プレースホルダを入力するために使用するオブジェクト。

リターン

String - フォーマット済み文字列。


getUuid()

UUID を文字列として取得します(java.util.UUID.randomUUID() メソッドを使用する場合と同等です)。この識別子は、すべての時間と空間で一意であるとは限りません。そのため、一意性を保証する必要がある状況では使用しないでください。

//This assigns a UUID as a temporary ID for a data object you are creating in your script.
var myDataObject = {
   tempId: Utilities.getUuid();
};

リターン

String - UUID の文字列表現。


gzip(blob)

指定された Blob データを gzip で圧縮し、新しい Blob オブジェクトに返します。

var textBlob = Utilities.newBlob("Some text to compress using gzip compression");

// Create the compressed blob.
var gzipBlob = Utilities.gzip(textBlob);

パラメータ

名前説明
blobBlobSourcegzip を使用して圧縮する Blob オブジェクト。

リターン

Blob - 圧縮データを含む新しい Blob


gzip(blob, name)

指定された Blob データを gzip で圧縮し、新しい Blob オブジェクトに返します。このバージョンのメソッドでは、ファイル名を指定できます。

var textBlob = Utilities.newBlob("Some text to compress using gzip compression");

// Create the compressed blob.
var gzipBlob = Utilities.gzip(textBlob, "text.gz");

パラメータ

名前説明
blobBlobSourcegzip を使用して圧縮する Blob オブジェクト。
nameString作成する gzip ファイルの名前。

リターン

Blob - 圧縮データを含む新しい Blob


newBlob(data)

バイト配列から新しい Blob オブジェクトを作成します。blob は、バイナリデータを入力として受け取る多くの Apps Script API で使用されます。

// Creates a blob object from a byte array.
const data = [71, 79, 79, 71, 76, 69];
const blob = Utilities.newBlob(data);

// Logs the blob data as a string to the console.
console.log(blob.getDataAsString());

パラメータ

名前説明
dataByte[]blob のバイト数。

リターン

Blob - 新しく作成された Blob。


newBlob(data, contentType)

バイト配列とコンテンツ タイプから新しい Blob オブジェクトを作成します。blob は、バイナリデータを入力として受け取る多くの Apps Script API で使用されます。

// Declares a byte array.
const data = [71, 79, 79, 71, 76, 69];

// Declares the content type of the blob.
const contentType = 'application/json';

// Creates a blob object from the byte array and content type.
const blob = Utilities.newBlob(data, contentType);

// Logs the blob data as a string to the console.
console.log(blob.getDataAsString());

// Logs the content type of the blob to the console.
console.log(blob.getContentType());

パラメータ

名前説明
dataByte[]blob のバイト数。
contentTypeStringblob のコンテンツ タイプ。null を指定できます。

リターン

Blob - 新しく作成された Blob。


newBlob(data, contentType, name)

バイト配列、コンテンツ タイプ、名前から新しい Blob オブジェクトを作成します。blob は、バイナリデータを入力として受け取る多くの Apps Script API で使用されます。

// Declares a byte array.
const data = [71, 79, 79, 71, 76, 69];

// Declares the content type of the blob.
const contentType = 'application/json';

// Declares the name of the blob.
const name = 'Example blob';

// Creates a blob object from the byte array, content type, and name.
const blob = Utilities.newBlob(data, contentType, name);

// Logs the blob data as a string to the console.
console.log('Blob data:', blob.getDataAsString());

// Logs the content type of the blob to the console.
console.log('Blob content type:', blob.getContentType());

// Logs the name of the blob to the console.
console.log('Blob name:', blob.getName());

パラメータ

名前説明
dataByte[]blob のバイト数。
contentTypeString- blob のコンテンツ タイプ。null を指定できます。
nameStringblob の名前は null です。

リターン

Blob - 新しく作成された Blob。


newBlob(data)

文字列から新しい Blob オブジェクトを作成します。blob は、バイナリデータを入力として受け取る多くの Apps Script API で使用されます。

// Declares a string for the blob.
const data = 'GOOGLE';

// Creates a blob object from a string.
const blob = Utilities.newBlob(data);

// Logs the blob data in byte array to the console.
console.log('Blob Data:', blob.getBytes());

パラメータ

名前説明
dataStringblob の文字列。UTF-8 と想定されます。

リターン

Blob - 新しく作成された Blob。


newBlob(data, contentType)

文字列とコンテンツ タイプから新しい Blob オブジェクトを作成します。blob は、バイナリデータを入力として受け取る多くの Apps Script API で使用されます。

// Declares a string for the blob.
const data = 'GOOGLE';

// Declares the content type of blob.
const contentType = 'application/json';

// Creates a blob object from the string and content type.
const blob = Utilities.newBlob(data, contentType);

// Logs the blob data in byte array to the console.
console.log('Blob data:', blob.getBytes());

// Logs the content type of the blob to the console.
console.log(blob.getContentType());

パラメータ

名前説明
dataStringblob の文字列。UTF-8 と想定されます。
contentTypeStringblob のコンテンツ タイプ。null を指定できます。

リターン

Blob - 新しく作成された Blob。


newBlob(data, contentType, name)

文字列、コンテンツ タイプ、名前から新しい Blob オブジェクトを作成します。blob は、バイナリデータを入力として受け取る多くの Apps Script API で使用されます。

// Declares a string for the blob.
const data = 'GOOGLE';

// Declares the content type of the blob.
const contentType = 'application/json';

// Declares the name of the blob.
const name = 'Example blob';

// Create a blob object from the string, content type, and name.
const blob = Utilities.newBlob(data, contentType, name);

// Logs the blob data in byte array to the console.
console.log('Blob data:', blob.getBytes());

// Logs the content type of the blob to the console.
console.log('Blob content type:', blob.getContentType());

// Logs the name of the blob to the console.
console.log('Blob name:', blob.getName());

パラメータ

名前説明
dataStringblob の文字列。UTF-8 と想定されます。
contentTypeStringblob のコンテンツ タイプ。null を指定できます。
nameStringblob の名前は null です。

リターン

Blob - 新しく作成された Blob。


parseCsv(csv)

CSV 文字列の表形式の 2D 配列表現を返します。

// This creates a two-dimensional array of the format [[a, b, c], [d, e, f]]
var csvString = "a,b,c\nd,e,f";
var data = Utilities.parseCsv(csvString);

パラメータ

名前説明
csvStringカンマ区切り値(CSV)形式の単一または複数行のデータを含む文字列。

リターン

String[][] - CSV 文字列の値を含む 2 次元配列。


parseCsv(csv, delimiter)

カスタムの区切り文字を使用して、CSV 文字列の表形式の 2D 配列表現を返します。

// This creates a two-dimensional array of the format [[a, b, c], [d, e, f]]
var csvString = "a\tb\tc\nd\te\tf";
var data = Utilities.parseCsv(csvString, '\t');

パラメータ

名前説明
csvStringカンマ区切り値(CSV)形式の単一または複数行のデータを含む文字列。
delimiterChar値の間。

リターン

String[][] - CSV 文字列の値を含む 2 次元配列。


parseDate(date, timeZone, format)

提供された文字列の日付を、Java Standard Edition SimpleDateFormat クラスの仕様に従って解析します。詳細については、Java の SimpleDateFormat クラスをご覧ください。

// This set of parameters parses the given string as a date in Greenwich Mean Time, formatted
// as year-month-dateThour-minute-second.
var date = Utilities.parseDate("1970-01-01 00:00:00", "GMT", "yyyy-MM-dd' 'HH:mm:ss");
Logger.log(date);

パラメータ

名前説明
dateString日付として解析する文字列値。
timeZoneString出力のタイムゾーン。
formatStringSimpleDateFormat 仕様に基づく日付形式。

リターン

Date - 日付としての入力文字列。


sleep(milliseconds)

指定したミリ秒数だけスリープします。スクリプトを直ちに指定したミリ秒数だけスリープさせます。指定できる最大値は 300,000(5 分)です。

// Creates a blob object from a string.
const data = 'GOOGLE';
const blob = Utilities.newBlob(data);

// Puts the script to sleep for 10,000 milliseconds (10 seconds).
Utilities.sleep(10000);

// Logs the blob data in byte array to the console.
console.log(blob.getBytes());

パラメータ

名前説明
millisecondsIntegerスリープする時間(ミリ秒)です。

ungzip(blob)

Blob オブジェクトを圧縮解除し、非圧縮データを含む Blob を返します。

var textBlob = Utilities.newBlob("Some text to compress using gzip compression");

// Create the compressed blob.
var gzipBlob = Utilities.gzip(textBlob, "text.gz");

// Uncompress the data.
var uncompressedBlob = Utilities.ungzip(gzipBlob);

パラメータ

名前説明
blobBlobSource圧縮データの Blob

リターン

Blob - 解凍データを表す Blob


unzip(blob)

zip ファイルを表す Blob を取得し、そのコンポーネント ファイルを返します。

var googleFavIconUrl = "https://www.google.com/favicon.ico";
var googleLogoUrl = "https://www.google.com/images/srpr/logo3w.png";

// Fetch the Google favicon.ico file and get the Blob data
var faviconBlob = UrlFetchApp.fetch(googleFavIconUrl).getBlob();
var logoBlob = UrlFetchApp.fetch(googleLogoUrl).getBlob();

// zip now references a blob containing an archive of both faviconBlob and logoBlob
var zip = Utilities.zip([faviconBlob, logoBlob], "google_images.zip");

// This now unzips the blobs
var files = Utilities.unzip(zip);

パラメータ

名前説明
blobBlobSourcezip ファイル blob。

リターン

Blob[] - コンポーネント blob を表す Blob[]。それぞれ zip 内のフルパスで名前が付けられています。


zip(blobs)

渡された Blob のデータを含む ZIP ファイルである新しい Blob オブジェクトを作成します。

var googleFavIconUrl = "https://www.google.com/favicon.ico";
var googleLogoUrl = "https://www.google.com/images/srpr/logo3w.png";

// Fetch the Google favicon.ico file and get the Blob data
var faviconBlob = UrlFetchApp.fetch(googleFavIconUrl).getBlob();
var logoBlob = UrlFetchApp.fetch(googleLogoUrl).getBlob();

// zip now references a blob containing an archive of both faviconBlob and logoBlob
var zip = Utilities.zip([faviconBlob, logoBlob]);

パラメータ

名前説明
blobsBlobSource[]圧縮する blob の配列。

リターン

Blob - 入力をアーカイブとして含む新しい blob。


zip(blobs, name)

渡された Blob のデータを含む ZIP ファイルである新しい Blob オブジェクトを作成します。このバージョンのメソッドでは、ファイル名を指定できます。

var googleFavIconUrl = "https://www.google.com/favicon.ico";
var googleLogoUrl = "https://www.google.com/images/srpr/logo3w.png";

// Fetch the Google favicon.ico file and get the Blob data
var faviconBlob = UrlFetchApp.fetch(googleFavIconUrl).getBlob();
var logoBlob = UrlFetchApp.fetch(googleLogoUrl).getBlob();

// zip now references a blob containing an archive of both faviconBlob and logoBlob
var zip = Utilities.zip([faviconBlob, logoBlob], "google_images.zip");

パラメータ

名前説明
blobsBlobSource[]圧縮する blob の配列。
nameString作成する ZIP ファイルの名前。

リターン

Blob - 入力をアーカイブとして含む新しい blob。

サポート終了のメソッド